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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

end function and return value

Status
Not open for further replies.

bdina

Programmer
Jun 17, 2003
47
0
0
US
I am writing a function that may have one of three possible outcomes. I would like for it to end processing once an outcome is reached and return the proper value. I know if I were doing this in C I could do something like this:

if(a==1)
{
return 1
}

if(a==2)
{
return 2
}

if(a==3)
{
return 3
}

Where when the variable a was 1, it would enter that branch, and rerturn the value 1, then stop execution. How do I do the same in VBScript (VB 6.0)??

thanks,
--Bryan
 
Something like this ?
Function NameOfFunction(a)
If a = 1 Then
NameOfFunction = 1
Exit Function
End If
...
NameOfFunction = WhatYouWant
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
In VBScript, the function name itself "looks like" a local variable.

Whatever value it has upon exit from the function is the return value.
Code:
Function MultiCon(ByVal Multiplier)
  MultiCon = 13.2
  MultiCon = MultiCon * Multiplier
End Function
I hope that makes it clearer. The function name is used to set the return value, and additionally within the function itself it may be used in expressions.
 
yeah, I found the answer right after posting this question, but that was exactly what I was looking for... thanks :)

--Bryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top