How do I combine variables into variable names?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
voodoogodman
Newbie
Posts: 4
Joined: Wed Jan 11, 2012 7:07 am

How do I combine variables into variable names?

Post by voodoogodman » Wed Jan 11, 2012 7:13 am

I am wondering how I can combine a variable(s) into a variable name?

Example script:

Code: Select all

Repeat>Card
  Let>Card=Card+1
  Repeat>Column
    Let>Column=Column+1
    Repeat>Row
      Let>Row=Row+1
      Let>Place_%Card%%Column%%Row%=1
    Until>Row,5
  Until>Column,5
Until>Card,3

I would like to have a bunch of variables named:
Place_111
Place_112
Place_113
Place_114
Place_115
Place_121
.
.
.
Place_355

All equal to 1 or whatever.

Help a noob.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jan 11, 2012 10:09 am

Exactly as you have done but you will need to intialise the loop counters:

Code: Select all

Let>Card=0
Repeat>Card
  Let>Card=Card+1
  Let>Column=0
  Repeat>Column
    Let>Column=Column+1
    Let>Row=0
    Repeat>Row
      Let>Row=Row+1
      Let>Place_%Card%%Column%%Row%=1
    Until>Row,5
  Until>Column,5
Until>Card,3
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

voodoogodman
Newbie
Posts: 4
Joined: Wed Jan 11, 2012 7:07 am

Post by voodoogodman » Wed Jan 11, 2012 4:07 pm

Thank you for your speedy reply.

If that looked good then I have another related issue concerning this same situation.

How could I get the value out and compare to another value.

Here's what I've got, but it doesn't work.
Or If I wanted to send> the value of Place_%CPCCard%%CPCColumn%%CPCRow% instead of comparing them.
It gives me an 'Unknown Identifier Place_111' Error
I tried %Place_%CPCCard%%CPCColumn%%CPCRow%% no good.
All the Place_*** variables have been initialized and given values in a previous subroutine. The watch list confirms this.

Code: Select all

Let>CPCCard=0
Let>CPCRow=0
Let>CPCColumn=0
Let>CallerBall=100
  Repeat>CallerBall
    Let>CallerBall=CallerBall+1
    Repeat>CPCCard
      Let>CPCCard=CPCCard+1
      Repeat>CPCColumn
        Let>CPCColumn=CPCColumn+1
        Repeat>CPCRow
          Let>CPCRow=CPCRow+1
          If>Place_%CPCCard%%CPCColumn%%CPCRow%=%CallerBall%
            Gosub>CheckForDaub
          endif
        Until>CPCRow,5
      Until>CPCColumn,5
    Until>CPCCard,3
  Until>Callerball,175
I'm trying to minimize how much of my code is made public. If you'd like me to send the complete code, I'd prefer to do it privately.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jan 11, 2012 4:59 pm

Like so:

Code: Select all

Let>CPCCard=0
Let>CPCRow=0
Let>CPCColumn=0
Let>CallerBall=100
  Repeat>CallerBall
    Let>CallerBall=CallerBall+1
    Repeat>CPCCard
      Let>CPCCard=CPCCard+1
      Repeat>CPCColumn
        Let>CPCColumn=CPCColumn+1
        Repeat>CPCRow
          Let>CPCRow=CPCRow+1
          Let>tmp_card=Place_%CPCCard%%CPCColumn%%CPCRow%
          If>tmp_card=%CallerBall%
            Gosub>CheckForDaub
          endif
        Until>CPCRow,5
      Until>CPCColumn,5
    Until>CPCCard,3
  Until>Callerball,175
(use Let to set a basic variable to the value of the array variable first, then use that in your If).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

voodoogodman
Newbie
Posts: 4
Joined: Wed Jan 11, 2012 7:07 am

Post by voodoogodman » Wed Jan 11, 2012 5:14 pm

You're awesome. Thank you so much.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts