Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return a calculated value from a Function Procedure

Status
Not open for further replies.

Numbers1

Technical User
Dec 27, 2003
34
US
Novice at VBA so bear with me.

Am trying to convert the number in a variable to another number and have to do this quite often so wrote a Function to do the calculation and return the result to the same variable.

Dim intInteger as Integer

Sub MainSub()
intInteger = 2
Convert (intInteger)

End Sub

Function Convert(ByVal number as Integer) as Integer

number = number * 4

End Function

How do I get the 'number' (2*4) 8 back into the MainSub and put it in the original intInteger or another variable?

Thanks, Numbers
 



Hi,
Code:
Sub MainSub()
intInteger = 2[b]
intInteger =[/b] Convert(intInteger)

End Sub

Function Convert(ByVal number as Integer) as Integer
[b]
Convert[/b] = number * 4

End Function

Skip,

[glasses] [red][/red]
[tongue]
 
hi Numbers,

Try:
Dim intInteger As Long

Sub MainSub()
intInteger = 2
Convert intInteger
MsgBox intInteger
End Sub

Function Convert(ByVal number As Integer) As Integer
intInteger = intInteger * 4
End Function

Cheers

[MS MVP - Word]
 
Another way:
[!]Sub[/!] Convert([!]ByRef[/!] number As Integer)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you all. Seems too easy, but try to find this is the help files!! Appreciate your input.
Numbers
 
try to find this is the help files
When in the debug window (Ctrl+G) type byref and press the F1 key.
Anyway I think you have to understand what a Function is.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top