PotterHarry

How to extract values from a script

20 posts in this topic

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 2.0.2.0**
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 :)

Share this post


Link to post
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. 

1 person likes this

Share this post


Link to post
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.  

1 person likes this

Share this post


Link to post
Share on other sites

You could just delete the first 7 characters then split on "Y:". Bam! Done. 

Share this post


Link to post
Share on other sites

I have made some progress .. 

1) How do I "pass" the values to an integer array variable

2) How can i get it to ignore the lines that start with a 5

3) What if the length of the number is only 3 digits (this will happen)?

Thanks!!

STRIP VALUES.mex

Share this post


Link to post
Share on other sites

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

Text File Begin Process: C:\1_temp\MouseRecorderPro2.txt
IF FIRST BYTE OF LINE IS NOT = 5
  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:
ENDIF
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. 

 

Share this post


Link to post
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 :-)

Share this post


Link to post
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. 

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

Using my split method it would not matter how many digits the numbers are. 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

And we're here to help you learn. 

Share this post


Link to post
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?

STRIP VALUES_2.mex

MouseRecorderPro2.txt

Share this post


Link to post
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. :)

Share this post


Link to post
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.

Share this post


Link to post
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%]%. 

Share this post


Link to post
Share on other sites

You're welcome.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now