Jump to content
Macro Express Forums

How to extract values from a script

Recommended Posts

Hi... below is a script section copied from Notepad.

What do I have to do to extract the values of X and Y into integer array variables? 


**Script version**
5    864
1    X:1701 Y:580
1    X:1700 Y:580
1    X:1692 Y:574
1    X:1687 Y:572
5    32
1    X:1678 Y:568
1    X:1664 Y:563
1    X:1648 Y:559
1    X:1636 Y:555
5    32
1    X:1621 Y:549
1    X:1603 Y:539
1    X:1555 Y:515
1    X:1523 Y:496
5    32
1    X:1484 Y:477
1    X:1440 Y:462
1    X:1391 Y:446
1    X:1286 Y:421


I will only waste hours if not days if I don't ask :)

Link to comment
Share on other sites

I would use Text File Process command if it's a file. Then in the loop I would use the Variable Modify String with the Copy Part of Text option. Simple. Assuming the X coordinate is always 4 digits of course. As per your sample. 

  • Like 1
Link to comment
Share on other sites

* Example of one line of data, in variable T1.  In your macro the Text File Process will populate the text variable, rather than the Set String command.
Variable Set String %T1% " X:1701 Y:580"

* Set integer to position of "X:" within the data
Variable Set Integer %N1% from Position of Text in Variable %T1%

* Bump position up by 2 characters so N1 is pointing to the first digit instead of to "X:"
Variable Modify Integer: %N1% = %N1% + 2

* What Cory said -- move four digits from the data to another variable
Variable Modify String: Copy Part of %T1% to %T2%  [starting position N1, number of digits 4]

* Display the extracted digits to verify the extraction is working properly
Text Box Display: %T2%

Of course in your actual macro, you would move the extracted digits to the array instead of Text Box Display.  

  • Like 1
Link to comment
Share on other sites

To ignore lines starting with 5, use an IF command.

Text File Begin Process: C:\1_temp\MouseRecorderPro2.txt
  Variable Set Integer %N[1]% to the position of "X" in %COORD[1]%
  Variable Modify Integer: %N[1]% = %N[1]% + 2
  Variable Modify String: Copy a substring in %COORD[1]%, starting at %N[1]% and 4 characters long to %TRIMX[1]%
  Text Box Display:
Text File End Process

Always copy 4 characters then VARIABLE MODIFY STRING (RIGHT-TRIM).  That will get rid of the trailing space if it turns out to be only 3 digits.  If it is 4 digits the trimming will have no effect. 


Link to comment
Share on other sites

PotterHarry you need to try things yourself at time. Read the help file.  Don't wait for others to show you the way. Make a test macro and try some things. Look at all the Variable Modify commands. Think about it an learn the capabilities. Experiment :-)

Link to comment
Share on other sites

I would tell you how to put values into an array, but I use Macro Express Version 3 which doesn't have arrays.:huh:

My guess would be, define an integer variable, increase it by one (Variable Modify Integer) each time through the Process loop, and use the variable as the index to the slots in the array. 

Link to comment
Share on other sites

TO answer your question about passing variable you set them as you do any variable. If you read the "Variables" section of the help file it explains. If you want to access directly %you can access any element of the array directly using the %VariableName[X]% convention where X is the element number. The split command will set them directly. If you need them as integers you will need to cast them with Variable Modify String > Convert to Integer. 

Link to comment
Share on other sites

Hi again. Of course I am learning all the time (as I'm sure we all are) but in my case evidently I'm a lot lower down the snakes and ladders board. I do have a working macro now, with some issues. I have used the length of the string to eliminate lines that do not contain x or y. I'll take a look at the split function suggested by Cory later when I get back from work.

Link to comment
Share on other sites

Hi again. Thanks Cory and rberq for your leads .. in the end I gave up on length of string in favour of sampling the first character. This macro does work very well, but the use of "If variable %LOOP[1]%" in lines 23-27 seems rather inelegant. Is there a more efficient way of passing these values to a predefined array?



Link to comment
Share on other sites

Usually, variable names bracketed by % can be substituted for literals.  

So instead of this:
  If Variable %LOOP[1]% Equals "2"
    Variable Modify Integer set %XCOORD[2]% to the contents of %TEMP[1]%

try this:
    Variable Modify Integer set %XCOORD[%LOOP[1]%]% to the contents of %TEMP[1]%

The script editor allows it, so it probably will work.  I hope so --  gets rid of all the IFs -- way more elegant. :)

Link to comment
Share on other sites

Text File End Process
Variable Save: Save All Variables
Mouse Move: 705, 641 Relative to Screen
Mouse Left Button Down
  Variable Set Integer %REPCOUNTER[1]% to 750
  Repeat Start (Repeat %REPCOUNTER[1]% times)
    Mouse Move: %XCOORD[%REPCOUNTER%]%, %YCOORD[%REPCOUNTER%]% Relative to Screen
    Delay: 0.1 seconds
  End Repeat
Mouse Left Button Up
Text Box Display: 

My mouse coordinates are now recording successfully. In the above code I'm seeing variable is the wrong type error on this line: Mouse Move: %XCOORD[%REPCOUNTER%]%, %YCOORD[%REPCOUNTER%]% Relative to Screen. They are all integer variables and they are defined.  Is my syntax incorrect? XCOORD and YCOORD are array variables with 750 elements. Thanks.

Link to comment
Share on other sites

You have something wrong. You have %REPCOUNTER% used as an array variable (REPCOUNTER[1]%) and as a singular variable (%REPCOUNTER%). It can't be both.

I think lines 5 and 6 should be using a different variable. Something like %Iterations%. Then you will repeat %Iterations% number of times and save the current iteration to something like %Index% in the repeat command. Then you would move to %XCOORD[%Index%]%, %YCOORD[%Index%]%. 

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.

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.

  • Create New...