PBasic programming: how create, concatenate & use string variables?
Flotul
Posts: 24
Hi,
I'm programming a loop calling subroutines. Unfortunately, I can't find the correct syntax. The idea is to concatenate the variable's name + a number (from the counter) but I don't know how to do this. So, here is what it looks like (i. e.) :
MAIN:
DO
idx = idx + 1 // 4 'counter
StringVar = "SubRoutine" + idx 'compose the subroutine's name, should be "SubRoutine0" ... "SubRoutine3"
GOSUB StringVar
LOOP
SubRoutine0:
'process something
RETURN
SubRoutine1:
'process something
RETURN
.....
Possible? Can somebody help?
Post Edited (Flotul) : 3/12/2006 2:33:17 PM GMT
I'm programming a loop calling subroutines. Unfortunately, I can't find the correct syntax. The idea is to concatenate the variable's name + a number (from the counter) but I don't know how to do this. So, here is what it looks like (i. e.) :
MAIN:
DO
idx = idx + 1 // 4 'counter
StringVar = "SubRoutine" + idx 'compose the subroutine's name, should be "SubRoutine0" ... "SubRoutine3"
GOSUB StringVar
LOOP
SubRoutine0:
'process something
RETURN
SubRoutine1:
'process something
RETURN
.....
Possible? Can somebody help?
Post Edited (Flotul) : 3/12/2006 2:33:17 PM GMT
Comments
MAIN:
··FOR idx = 0 TO 3
· ON idx GOSUB ROUT1, ROUT2, ROUT3, ROUT4
· NEXT
· END
ROUT1:
· 'do this
· RETURN
ROUT2:
· 'do that
· RETURN
ROUT3:
· 'do the other
· RETURN
ROUT4:
· 'just do something
· RETURN
·
I thank you very muchfor your help; that's a good way to solve my problem.
Nevertheless, I was used years ago to progam under DBase/Clipper and it was quite easy to convert strings to other data formats.
Now, with PBasic, I don't know if the same conversion is possible.
Any idea?
· A subroutine name can't include a variable.
· This will not work: a = 150
················· ··· GOTO ROUTa
·
Thanks again
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax