Increment Variable Name based on loop

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Increment Variable Name based on loop

Post by RNIB » Tue Sep 19, 2017 10:43 am

I'm trying to copy the names of files and store them as variables for later comparison. I had intended to do this using a loop command but the variables aren't being captured in that if I messagemodal them, I just get the name of variable and not what should be in the variable.

This is a heavily edited version of the macro removing parts of the code that do other things unrelated to this function.
//Count the number of WAV files in the source directory
CountFiles>F:\116CP Woman 170918\Newsagent\Side 1\*.wav,WavCount1,0
//Open Marker List
Press Alt
Send>8
Release Alt
Wait>1
MouseMoveRel>430,119
LClick
Wait>1
Press Home
//Copy Description of all tracks in first file
Let>loop=0
Repeat>loop
Let>loop=loop+1
Press Tab *7
Wait>0.5
Press Ctrl
send>c
Release Ctrl
WaitClipBoard
GetClipBoard>description1_%loop%
Wait>0.5
Press Tab
Press Down
Wait>0.5
Until>loop=WavCount1
//I know that in this test the number of WAV files in the source directory is 10
MessageModal>Side 1%CRLF%Description 1=description1_1%CRLF%Description 2=description1_2%CRLF%Description 3=description1_3%CRLF%Description 4=description1_4%CRLF%Description 5=description1_5%CRLF%Description 6=description1_6%CRLF%Description 7=description1_7%CRLF%Description 8=description1_8%CRLF%Description 9=description1_9%CRLF%Description 10=description1_10
Everything seems to work in that it will seemingly tab through and copy the names of each file but the message at the end appears like this:

Side 1
Description 1=description1_1
Description 2=description1_2
Description 3=description1_3
Description 4=description1_4
Description 5=description1_5
Description 6=description1_6
Description 7=description1_7
Description 8=description1_8
Description 9=description1_9
Description 10=description1_10

So the variable name is being incremented by the loop but it doesn't contain the content of the clipboard

I'm presuming that it doesn't like putting a loop value in the name of a variable but I don't know how else to generate unique variables as the number of files to copy will be different every time.

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

Re: Increment Variable Name based on loop

Post by Marcus Tettmar » Tue Sep 19, 2017 11:51 am

You don't have those variables in % symbols. You need:

MessageModal>Side 1%CRLF%Description 1=%description1_1%%CRLF%Description 2=%description1_2%%CRLF%... etc
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Increment Variable Name based on loop

Post by RNIB » Tue Sep 19, 2017 12:01 pm

:oops: :oops:
Ahh, yes, oops.

In my defense I copied and pasted into a temporary script to hack it around and added the messagemodal command at the last minute.

However in my original script the variables are between %%.

I've tried adding them in the test script as well but it still doesn't work in either. Both times it just says:

Side 1
Description 1=%description1_1%
Description 2=%description1_2%
Description 3=%description1_3%
Description 4=%description1_4%
Description 5=%description1_5%
Description 6=%description1_6%
Description 7=%description1_7%
Description 8=%description1_8%
Description 9=%description1_9%
Description 10=%description1_10%

If I manually copy each file by hand they are being copied so it's not that these names can't be copied just that for some reason they aren't being saved into the variable. I'm sure I'm doing something basic wrong but I just can't see what.

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

Re: Increment Variable Name based on loop

Post by Marcus Tettmar » Tue Sep 19, 2017 12:07 pm

Aah I see it now. You need to do this:

GetClipBoard>tmpClipboard
Let>description_%loop%=tmpClipboard

You need to use Let to assign to embedded array type variables.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Increment Variable Name based on loop

Post by RNIB » Tue Sep 19, 2017 1:02 pm

Aha! Yep that fixed it.

Cheers Marcus, much appreciated.

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