Passing array variable to a function

136 views
Skip to first unread message

Sitaneph

unread,
Sep 20, 2016, 10:58:55 PM9/20/16
to MapInfo-L
I have a number of popupmenu controls on a dialog and hence quite a few string array variables. I want to create a single function to get the integer value for a given string and string array. I currently have a function for each string array that looks like this:

Function GetTreatEffect_Num(byval sInput as string) as integer
'this function is used with the global array variables to populate the popupmenu
'items on the dialog box

Dim counter as integer

For counter = 1 to ubound(sWTreatEffect)
if sWTreatEffect(counter) = sInput then
GetTreatEffect_Num = counter
Exit Function
End if
Next

GetTreatEffect_Num = 0

End Function

I would like to have the string array name as a variable passed into the function rather than hard coded into the function. However i can't figure out how to setup the variable so that i can still use it as a string array. Which is to say, this does not work:

Function GetTreatEffect_Num(byval sInput as string, StringArrayName) as integer

Dim counter as integer

For counter = 1 to ubound(StringArrayName)
if StringArrayName(counter) = sInput then
GetTreatEffect_Num = counter
Exit Function
End if
Next

GetTreatEffect_Num = 0

End Function

Peter Horsbøll Møller

unread,
Sep 21, 2016, 2:20:07 AM9/21/16
to mapi...@googlegroups.com

Try:

 

Function GetTreatEffect_Num

( ByVal sInput as String

, StringArrayName() As String

) as integer

 

Arrays must always be send by reference as parameters and you need to end the parameter name with a closed parenthesis to tell the compiler it’s an array.

 

Peter Horsbøll Møller

EMEA Channel Enablement Specialist

Location Intelligence | MapInfo

 

M: +45 29 133 769

peter....@pb.com | @phorsbollmoller

pitneybowes.com/dk | mapinfo.com

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to
mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.




Reply all
Reply to author
Forward
0 new messages