How to write a function?

polina

Registered User.
Local time
Today, 11:30
Joined
Aug 21, 2002
Messages
100
Hi,

I have a very generic question
Can anyone give me an example of the VBA function and funciton call

I need to pass parameter to function ByRef and then return three parameters back to the place where the function was called from

Thanks.
 
Code:
Public Sub TestMyFunc()
   Dim stFirst as String
   Dim stSecond as String
   Dim stThird as String
   Dim Return as Boolean

   'Method One get the Return Value
   Return = fTest(stFirst,stSecond,stThird)
   Debug.Print "stFirst = " & stFirst
   Debug.Print "stSecond = " & stSecond
   Debug.Print "stThird = " & stThird

   'Method Two, no return value
    Call fTest(stFirst,stSecond,stThird)
   Debug.Print "stFirst = " & stFirst
   Debug.Print "stSecond = " & stSecond
   Debug.Print "stThird = " & stThird

End Sub

Public Function fTest(ByRef stVal1 as String,ByRef stVal2 as String,ByRef stVal3 as String) as Boolean
On Error Goto ErrorHandler
stVal1="This is"
stVal2="a"
stVal3="test."
fTest=True

Exit Function
ErrorHandler:
  fTest=False
End Function
 

Users who are viewing this thread

Back
Top Bottom