PotterHarry Posted June 8, 2017 Report Share Posted June 8, 2017 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 Quote Link to comment Share on other sites More sharing options...
Cory Posted June 8, 2017 Report Share Posted June 8, 2017 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 Quote Link to comment Share on other sites More sharing options...
rberq Posted June 8, 2017 Report Share Posted June 8, 2017 * 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 Quote Link to comment Share on other sites More sharing options...
Cory Posted June 8, 2017 Report Share Posted June 8, 2017 You could just delete the first 7 characters then split on "Y:". Bam! Done. Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted June 9, 2017 Author Report Share Posted June 9, 2017 Thanks both for your help .. I'll give it a try later. Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted June 9, 2017 Author Report Share Posted June 9, 2017 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 Quote Link to comment Share on other sites More sharing options...
rberq Posted June 9, 2017 Report Share Posted June 9, 2017 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 10, 2017 Report Share Posted June 10, 2017 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 :-) Quote Link to comment Share on other sites More sharing options...
rberq Posted June 11, 2017 Report Share Posted June 11, 2017 I would tell you how to put values into an array, but I use Macro Express Version 3 which doesn't have arrays. 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 12, 2017 Report Share Posted June 12, 2017 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 12, 2017 Report Share Posted June 12, 2017 Using my split method it would not matter how many digits the numbers are. Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted June 12, 2017 Author Report Share Posted June 12, 2017 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 12, 2017 Report Share Posted June 12, 2017 And we're here to help you learn. Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted June 12, 2017 Author Report Share Posted June 12, 2017 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 Quote Link to comment Share on other sites More sharing options...
rberq Posted June 12, 2017 Report Share Posted June 12, 2017 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. Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted June 13, 2017 Author Report Share Posted June 13, 2017 Elegant is not the word...it works!! Thanks. Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted June 13, 2017 Author Report Share Posted June 13, 2017 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 13, 2017 Report Share Posted June 13, 2017 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%]%. Quote Link to comment Share on other sites More sharing options...
PotterHarry Posted June 14, 2017 Author Report Share Posted June 14, 2017 That did it Cory..thanks very much. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 14, 2017 Report Share Posted June 14, 2017 You're welcome. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.