Returning value from function

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
 
B

Brad

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
 
R

Robin Hammond

Option Explicit

Function testee(X) as integer
X = 1 + 1
testee = X
End Function
 
J

James S

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top