View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_2087_] Rick Rothstein \(MVP - VB\)[_2087_] is offline
external usenet poster
 
Posts: 1
Default Parameter Pasing ?

In VB/VBA, functions pass their values back through the function's name. Try
your code this way...

Private Sub CommandButton1_Click()
para_ret = Test()
MsgBox "x is " & para_ret
End Sub

Function Test()
Test = 12
End Function

Notice that this simple Test function did not need any arguments; however,
you could have provided them if there were calculation within the function
that relied on non-global values outside of it.

Rick



"Eng Teng" wrote in message
...
How do I get x value from Function Test() in CommandButton1_Click()
function ?

Function Test(ByVal x As Integer)
x = 12
End Function

Private Sub CommandButton1_Click()
para_ret = Test(x)
MsgBox "x is " & para_ret
End Sub

Regards,
Tee