Returning value from function

  • Thread starter Thread starter Sally
  • Start date Start date
S

Sally

I don't understand how to return a value from a function. If I wanted to
return the value for X in testee to test, how can I fix this code?

Sub test()
Dim X As Integer
X = 1
testee (X)
MsgBox X
End Sub

Function testee(X)
X = 1 + 1
End Function
 
The function itself becomes the return value.

Sub test()
dim x as integer
x = 1
x = testee(x)
msgbox x
End Sub

Function testee(x as integer) as integer
testee = x + 1
End function

-Brad
 
Hi Sally,

I've listed another example below.

Hope it helps.

Regards,
James S

Sub Test()
Dim x As Integer
x = 1
MsgBox "New value = " & GetNewValue(x)
End Sub

Function GetNewValue(x As Integer) as Integer
GetNewValue = x + 1
End Function
 
Back
Top