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

return without gosub on new function

Status
Not open for further replies.

raileyb

Programmer
Apr 9, 2005
13
US
I feel like such a dummy, but I can't get this simple function to work. I wanted to write a function, called Num2Name, that accepts a value, evaluates it, and returns a string based on the number.
See below:
Public Function Num2Name(ValveNumber)
Select Case ValveNumber
Case "2"
Return 'hypokinetic'
Case "3"
Return 'akinetic'
Case "4"
Return 'dyskinetic'
Case "5"
Return 'aneurysm'
Case "9"
Return 'not well visualized'
Case Else
'do nothing
End Select
End Function

I would call this function like the following:
lTIapicalseptal = Num2Name(Trim(Forms!frmtests.frmBApical!apicalseptal))

thinking it would replace the value of the form field with a string.

Instead I get an error, 'return without gosub', and I'm sure it's a simple syntax issue, but I am stumped.
 
Other languages use the "Return" statement, in VB(A), you "assign to the function":

[tt]Public Function Num2Name(ValveNumber) as string
dim strReturn as string
Select Case ValveNumber
Case "2"
strReturn = "hypokinetic"
Case "3"
strReturn = "akinetic"

...

End Select
Num2Name = strReturn
End Function[/tt]

Now you're passing a variant - if it's numeric:

[tt]Public Function Num2Name(ValveNumber as long) as string
...
Case 2
...[/tt]

Roy-Vidar
 
Thank you, picking up vba after 20 years of other languages lulls me into a false sense of security.
Here's your star for a fast, accurate tek tip!

taz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top