Reading and assignin variables

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Reading and assignin variables

Post by kpassaur » Fri May 25, 2007 8:15 pm

I'll start by explaining what I want to do and maybe someone who hasn't stared at this as long as me can figure it out. It should only be a one or two line fix.

I want to read a text file that contains

A name that will be come a variable - a line number (to be read in a text file) and the start postion and length of the data to be parsed. Such as this

value1;7;24;7
value2;24;59;17
etc. no limit on number of lines being read

No Problem so far, the script below does this

Deletefile>C:\consolegrab\parsed.txt
Let>z=1
Label>starttest
ReadLn>c:\consolegrab\capturesettings.txt,z,settings
If>settings=##EOF##,finishtest
Separate>%settings%,;,processline
Let>valuename=%processline_1%
ReadLn>C:\consolegrab\clean.txt,%processline_2%,haveline
MidStr>%haveline%,%processline_3%,%processline_4%,valuecaptured
WriteLn>C:\consolegrab\parsed.txt,vresult,%valuename%=%valuecaptured%
Let>z=z+1
Goto>starttest
Label>finishtest

The output in the text file looks like this

value1=test one
value2=test two

Just like you would expect if "test one" was in the position specified in the line being read. However what I want is a variable called "value1" to contain the value "test one" and a variable called value2 to contain "test two". This is because value1 maybe called something else like "FirstName" and I want whatever is on the line being read before the line numbers to be the variable name.

So in a nutshell it is read a line, get a value from that line which will become the name of a variable and assign a value to the variable, read the next line and do it again.

Hopefully I explained this correctly. I am sure I am missing something simple like the VAREXPLICIT command which I somewhat get.

Any ideas

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri May 25, 2007 9:12 pm

Let>a=apple
Let>%a%=red delicious

Something like that?

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

I'm still not getting the assigning part

Post by kpassaur » Fri May 25, 2007 9:56 pm

JRL

I'm still not getting it

Here is where I am puzzled, I need the text in %processline_1% to become a variable name and assign a value to it, as it is now each time it cycles thorough valuename is just equal to %processline_1%, next time through it is updated

Let>valuename=%processline_1%

For instance

If %processline_1% contains Bob, now valuename contains Bob. But I want a variable calle %Bob% and assign a value to it.

Next time through it won't be "Bob" in %processline_1% it will be "Fred"
so I will end up with %Fred% containing text.

Perhaps adding a counter to valuename then resigning it?

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri May 25, 2007 10:32 pm

Sorry for being vague.

Took your code and added tildes to your filenames so I wouldn't interfere with your real data. Other than creating and deleting files and fake data in the first nine lines, I've added one line Let>%valuename%=%valuecaptured%. This line sets the variable valueX (whose name was returned from the text file) and assigns a value to it.
Deletefile>C:\consolegrab\~parsed.txt
DeleteFile>C:\consolegrab\~capturesettings.txt
DeleteFile>C:\consolegrab\~clean.txt
WriteLn>C:\consolegrab\~capturesettings.txt,wresult,value1;1;2;7
WriteLn>C:\consolegrab\~capturesettings.txt,wresult,value2;2;4;7
WriteLn>C:\consolegrab\~capturesettings.txt,wresult,value3;3;8;7
WriteLn>C:\consolegrab\~clean.txt,wresult,123456789abcdefg
WriteLn>C:\consolegrab\~clean.txt,wresult,123456789abcdefg
WriteLn>C:\consolegrab\~clean.txt,wresult,123456789abcdefg
Wait>1

Let>z=1
Label>starttest
ReadLn>c:\consolegrab\~capturesettings.txt,z,settings
If>settings=##EOF##,finishtest
Separate>%settings%,;,processline
Let>valuename=%processline_1%
ReadLn>C:\consolegrab\~clean.txt,%processline_2%,haveline
MidStr>%haveline%,%processline_3%,%processline_4%,valuecaptured
WriteLn>C:\consolegrab\~parsed.txt,vresult,%valuename%=%valuecaptured%

Let>%valuename%=%valuecaptured%

Let>z=z+1
Goto>starttest
Label>finishtest
MDL>%value1% %value2% %value3%
Hope this helps make things a little more clear.

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Assiging vairables

Post by kpassaur » Fri May 25, 2007 10:48 pm

JRL

You are good, there is no doubt about that. I just figured it out after 10 hours, then I get your email, and you master it in how long?

Thank you for your assistance. I think this will end up as the best thing I have ever created. It will allow the user to have an easy setup, (very easy) capture and parse any screen data they want and use it any way they want.

I have been working on the concept for 3 years and I am very close to perfecting it.

The key was always in two things the way I look at it. One an easy screen capture, (which I now have) and second an easy way for a "technology challenged person" to parse data. This will be it, the setup allows them to capture a screen (very easy it captures just about anything on the active window), display the text captured, and then with their mouse they just highlight what ever they want to capture, asign it a variable name of their choice for later use.

It is looking very promising.

Thanks again.

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