Jump to content
Macro Express Forums

Loop With Changing Variables


Avarion

Recommended Posts

Hi, again. I have a problem with loops.

 

The point is: The macro contains a series of variables like N20-N30. Now I have a loop and inside the macro shall take the loopcounter N1 and add 20. Then take the number to get the matching variable and put the content in variable N40.

 

Sample:

 

N1=0

N20=4

N21=6

N22=342

N23=12

 

1. loop N1=1, N40=5 (N1+N20)

2. loop N1=2, N40=8 (N1+N21)

3. loop N1=3, N40=345 (N1+N22)

4. loop N1=4, N40=16 (N1+N23)

 

I am not able to mix the variable name and variable content. I dont find any infos in the ME-help. Idea anyone ?

Link to comment
Share on other sites

Hello Avarion!

 

You need to familiarize yourself with dynamic program execution. Here is your example:

 

// Set variables N20 through N30 to random integer values.
Variable Set Integer %N20% to 4
Variable Set Integer %N21% to 6
Variable Set Integer %N22% to 342
Variable Set Integer %N23% to 12
Variable Set Integer %N24% to 56
Variable Set Integer %N25% to 47
Variable Set Integer %N26% to 9
Variable Set Integer %N27% to 69
Variable Set Integer %N28% to 11
Variable Set Integer %N29% to 22
Variable Set Integer %N30% to 19

// Launch and/or activate the Windows Notepad.
Activate or Launch: "notepad" OR "notepad.exe"
Delay 500 Milliseconds

// Repeat 11 times (number of random variables). Save the current counter in N1.
Repeat Start (Repeat 11 times)
 
 // Set N2 to the current counter+19, which gives us 20,21,22,23,...
 Variable Modify Integer: %N2% = %N1% + 19
 
 // Generate a Macro Express command string to run.
 Variable Set String %T1% "<NMVAR:01:40:1:0000001:1:00000%N2%>"
 
 // Dynamically run the command string.
 Run Macro in Variable %T1%
 
 // Type out the values each time through the loop.
 Text Type: N1 = %N1%<ENTER>N2 = %N2%<ENTER>T1 = %T1%<ENTER>N40 = %N40%<ENTER><ENTER>
 Delay 250 Milliseconds
 
Repeat End
Macro Return


<REM2:Set variables N20 through N30 to random integer values.><IVAR2:20:01:4><IVAR2:21:01:6><IVAR2:22:01:342><IVAR2:23:01:12><IVAR2:24:01:56><IVAR2:25:01:47><IVAR2:26:01:9><IVAR2:27:01:69><IVAR2:28:01:11><IVAR2:29:01:22><IVAR2:30:01:19><REM2:><REM2:Launch and/or activate the Windows Notepad.><LAUNCHYES3:0:0112notepad<LAUNCH:notepad.exe><IMSD:500><REM2:><REM2:Repeat 11 times (number of random variables). Save the current counter in N1.><REP3:01:000001:000001:00011:1:01:><REM2:><REM2:Set N2 to the current counter+19, which gives us 20,21,22,23,...><NMVAR:01:02:1:0000001:2:0000019><REM2:><REM2:Generate a Macro Express command string to run.><TVAR2:01:01:<NMVAR:01:40:1:0000001:1:00000%N2%>><REM2:><REM2:Dynamically run the command string.><RUNMACVAR:1><REM2:><REM2:Type out the values each time through the loop.><TEXTTYPE:N1 = %N1%<ENTER>N2 = %N2%<ENTER>T1 = %T1%<ENTER>N40 = %N40%<ENTER><ENTER>><IMSD:250><REM2:><ENDREP><MRETURN>

Link to comment
Share on other sites

Well, it means nothing when you copy and paste it into a macro. However, the correct command line is generated each time through the loop when the macro runs. The first time through the loop it will be evaluated as:

 

Variable Modify Integer: %N40% = %N1% + %N20%

 

the next time it will be:

 

Variable Modify Integer: %N40% = %N1% + %N21%

 

and then :

 

Variable Modify Integer: %N40% = %N1% + %N22%

 

and so it goes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...