Return Value from Function

D

Dan

Hello. I have a function in a module, and I'd like to return a value from it
into the sub routine that called it. For some reason, I'm having some
trouble with this. Can anyone point me in the right direction? Thanks.
 
A

Alex White MCDBA MCSE

Hi Dan,

this is a sub (no return value)

sub test(myvar as string)

end sub



this is a function

function test(myvar as string) as string

test = "hello " & myvar
end function

that will return the string to the calling function


how are each called

the sub

call test("alex")

the function

dim myRetStr as string
myRetStr = test("alex")
msgbox myRetStr

Hope that answers your question.
 
O

Ofer

sub RunFunction()
dim MyReturnValue as string

MyReturnValue = MyFunction()
msgbox MyReturnValue
' you will get msg box with xxxxxxx the value sent from the function
end sub

function MyFunction() as string
MyFunction = "xxxxxxx"
end function
 
D

David C. Holley

1. Always post the code in question.

2. Double check that your setting the value for the function in a
statement similar to

function getName()
getName = "Arthur Dent"
end function
 
Top