Shop OBEX P1 Docs P2 Docs Learn Events
PBasic programming: how create, concatenate & use string variables? — Parallax Forums

PBasic programming: how create, concatenate & use string variables?

FlotulFlotul Posts: 24
edited 2006-03-14 01:14 in General Discussion
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

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-03-12 18:06
    I think that what you want to do is use ON...GOTO or ON...GOSUB

    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
    ·
  • FlotulFlotul Posts: 24
    edited 2006-03-12 19:10
    Hi Allen,

    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?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-03-12 19:25
    · I think that what you propose (like synthesizing subroutine names from various data elements) is not possible with PBASIC.

    · A subroutine name can't include a variable.
    · This will not work: a = 150
    ················· ··· GOTO ROUTa
    ·
  • FlotulFlotul Posts: 24
    edited 2006-03-12 19:44
    Okay, so it's clear.

    Thanks again smile.gif
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-14 01:14
    DBase and Clipper were designed for BIG machines (PCs), PBASIC for a very small machine (BASIC Stamp). That said, you'll find that PBASIC offers solutions that you need -- just taking a different route. In addition to ON..GOTO and ON...GOSUB, PBASIC also supports SELECT..CASE, which may be more familiar to you coming from a PC background.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.