Using a map value to call a sub

MDEnt

Member
Licensed User
Longtime User
Hey all, great support and info in these forums.

I'm writing an integer value (PageNumber) in a map, and reading it later to return a user to the last viewed panel

I pull the value from the map and verify the value is correct with a messagebox. I then want to do something like LoadPageX (which would call LoadPage3 if the value were 3).

I'm having trouble with the correct syntax to place the value from the map into the X to get the panel loaded.


Sub LoadPage3
Misc. code...
End Sub
 

stevel05

Expert
Licensed User
Longtime User
I don't think you can call a Sub from a variable, you'll need to use a set of If then's or a Select block that does something like:

Select PageNumber

Case "1"

LoadPage1

Case "2"

LoadPage2

.
.
.

End Select

Steve
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Nice.. I'm sure I'll need it at some stage.

Thanks

Steve
 
Upvote 0

MDEnt

Member
Licensed User
Longtime User
Thanks - I tried the select block - and it works great - but many lines of code to manage due to the number of variables I can pass. I'm using it in the meantime until I can figure out the correct callsub syntax.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Thanks - I tried the select block - and it works great - but many lines of code to manage due to the number of variables I can pass. I'm using it in the meantime until I can figure out the correct callsub syntax.

Assuming that the subs are part of the same module, and that your subs are called LoadPage1, LoadPage2 etc then:
B4X:
CallSub("", "LoadPage"&PageNumber)
should work fine.
 
Upvote 0
Top