Defining multiple VBA objects within one function or sub-routine?
        Posted  
        
            by 
                Harokitty
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Harokitty
        
        
        
        Published on 2012-09-05T05:46:18Z
        Indexed on 
            2012/09/05
            9:38 UTC
        
        
        Read the original article
        Hit count: 260
        
I have the following VBA code:
Option Explicit
Private a(2) as Double
Private b(2) as Double
Public Function Hello(X1 As Double, X2 As Double) As Double
    a(1) = X1 + X2
    a(2) = X1/X2
    b(1) = X1
    b(2) = X2^2
Hello = a(1)+a(2)+b(1)+b(2)
End Function
Within the function Hello I have defined a(1),a(2),b(1),b(2).
However, I want to make some function or sub-routine that accepts X1 and X2 as arguments and spits out the values for a(1),a(2),b(1),b(2). This is because I use the above definitions for a(1),a(2),b(1),b(2) in about 20 functions in my module and would like to avoid having to do the following in each function that I use thesis in:
    a(1) = X1 + X2
    a(2) = X1/X2
    b(1) = X1
    b(2) = X2^2
© Stack Overflow or respective owner