how do i return value from module's function?

beefwellington

Registered User.
Local time
Yesterday, 21:08
Joined
Jul 27, 2009
Messages
14
I made a Public Function in a module, called Toolbox, where I wanted to place a lot of reusable code. I have the following function in the module:

Code:
Public Function test(anInt As Integer) As Integer
    anInt = anInt + 5
End Function

I've tried to execute the function these 2 ways:

Code:
    Dim anInt As Integer
    Dim toolbox As Module
    anInt = 1
    toolbox = Modules!toolbox
    anInt = toolbox.test(anInt)
    MsgBox anInt

which returns an error on toolbox.test(anInt), and:

Code:
    Dim anInt As Integer
    anInt = 1
    anInt = toolbox.test(anInt)
    MsgBox anInt

which returns anInt = 0 instead of 6.

I'm not sure what I'm doing wrong here so any help would be appreciated.
 
It should just be:
Code:
    Dim anInt As Integer
    anInt = 1
    anInt = test(anInt)
    MsgBox anInt
 
A Function be definition returns a value, so try changing the Function to look like the following:
Code:
[B]Public Function test(anInt As Integer) As Integer[/B]
[B]   [COLOR=red]test[/COLOR] = anInt + 5[/B]
[B]End Function[/B]

I see that BobLarson has beaten me to the post again with a different idea. In the event that what he suggests does not work (a long shot at best), you can always try mine. post back if you have additional questions.
 
Last edited:
A Function be definition returns a value, so try changing the Function to look like the following:
Code:
[B]Public Function test(anInt As Integer) As Integer
    [COLOR=red]test[/COLOR] = anInt + 5
End Function[/B]

Oops! Good tag team effort. With the combination they should be good to go. I missed that part of it :o
 
I love you guys :P It works like a charm after I did both of your suggestions :D Thanks!!
 

Users who are viewing this thread

Back
Top Bottom