COMBO VARIABLE NOT WORKING

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

rusty9075
Newbie
Posts: 14
Joined: Sun Aug 27, 2006 4:46 pm

COMBO VARIABLE NOT WORKING

Post by rusty9075 » Sun Aug 27, 2006 4:56 pm

Hi,

I am trying to create a macro that will repeat several times and create a unique variable each time it repeats. I created this code thinking that it would work, but instead of creating a unique variable. In this example code. I was hoping that "y" would equal "line1c" and thus print the text for variable "line1c" Instead it just creates the text : %line1c%. Can anyone help me and tell me whats wrong with this code???

Thanks


let>a=14
let>kkkk=0
repeat>kkkk
let>kkkk=kkkk+1
let>a=a+1
let>x=line%kkkk%b
let>y=line%kkkk%c



readln>C:\\cafe\flag.txt,%a%,firstline




length>firstline,len
Position> ,firstline,1,start,FALSE
let>start2=start+2
Midstr>firstline,start2,len,%y%
Midstr>firstline,start,len,linex
Midstr>firstline,1,len,%x%
StringReplace>%x%,linex,,%x%


send text>%line1c%

until>kkkk=40

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Aug 27, 2006 5:00 pm

Hi,

I don't follow what you are trying to do. If you can explain what you want to achive we may be able to help you achive it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sun Aug 27, 2006 7:27 pm

I think what rusty9075 wants to do is programatically generate variable names, line1b, line2b, line3b etc., line1c, line2c, line3c etc. and then assign text values to those variables.

I don't know if there is a way to do that, but the better/simpler way to do this would be to use two arrays,

linec[%kkk%] and lineb[%kkk%]

then the MidStr looks like:

Midstr>firstline,start2,len,linec[%kkk%]

There are lots of array examples on here, just search on "array"

rusty9075
Newbie
Posts: 14
Joined: Sun Aug 27, 2006 4:46 pm

COMBO VARIABLE NOT WORKING

Post by rusty9075 » Mon Aug 28, 2006 5:41 am

Hi Me_Again.

Yes, that is what I'm trying to do, create line1c, line1b,line3c...etc variables. I changed my code to follow the array setup:


let>a=14
let>kkkk=0
repeat>kkkk
let>kkkk=kkkk+1
let>a=a+1




readln>C:\\cafe\flag.txt,%a%,firstline



length>firstline,len
Position> ,firstline,1,start,FALSE
let>start2=start+2
Midstr>firstline,start2,len,linec[%kkkk%]
Midstr>firstline,start,len,linex
Midstr>firstline,1,len,lineb[%kkkk%]
StringReplace>lineb[%kkkk%],linex,,lineb[%kkkk%]



until>kkkk=40

send text>%linec1%


I was hoping this would create variables linec1, linec2, linec3...etc. However, the "send text>%linec1%" results in typing the text "%linec1%" instead of typing the variable text it represents. Do you know what I'm doing wrong???

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 28, 2006 8:28 am

Only the Let command can create/modify array/complex type variables (variables with other embedded variables within them). So you need to use this approach:

Code: Select all

Let>kkkk=1234
Let>firstline=1234567AAAHHH
Length>firstline,len
Midstr>firstline,1,len,temp
StringReplace>temp,linex,,temp

Let>lineb[%kkkk%]=temp
i.e. use an ordinary temporary variable for the operation and then finally assign it's contents to your complex variable.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Re: COMBO VARIABLE NOT WORKING

Post by Me_again » Mon Aug 28, 2006 1:32 pm

rusty9075 wrote:Hi Me_Again.

send text>%linec1%


I was hoping this would create variables linec1, linec2, linec3...etc. However, the "send text>%linec1%" results in typing the text "%linec1%" instead of typing the variable text it represents. Do you know what I'm doing wrong???
That would be:

send text>%linec[1]%

But if you absolutely need the variable names without the [] then Marcus Let> method would be the way to go.

rusty9075
Newbie
Posts: 14
Joined: Sun Aug 27, 2006 4:46 pm

COMBO VARIABLE NOT WORKING

Post by rusty9075 » Mon Aug 28, 2006 8:40 pm

Hi

Me_Again, unfortunately changing the send text to:

send text>%linec[1]%

just resulted in the text "%linec[1]% appearing rather than the varible information.
However, the method from Marcus did work. THANK YOU BOTH SO MUCH!!! YOU GUYS ROCK!!!


I have another challege if your up to it. I was wondering how to copy a file and then paste that file's text information without actually opening the file. This is what I tried:


readfile>C:\\cafe\flag.txt,file


send text>%file%

Unfortunately when I run this program with a Microsoft Word Document open, MacroScheduler goes crazy and tries to do all sorts of weird things like printing the page, weird symbols, etc.
The flag.txt is a text file, but the text does contain html code. Do you know how I can read a file or copy a file without physically opening it and pasting that text on a open word document or internet box?

Thanks for your help
:)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 28, 2006 9:13 pm

Unfortunately when I run this program with a Microsoft Word Document open, MacroScheduler goes crazy and tries to do all sorts of weird things like printing the page, weird symbols, etc.
That would most likely be because you're sending that text to the wrong control or window. Consider what would happen if Word's toolbar, or menu had the focus and you sent the contents of a file to it - a whole heap of crazy stuff would happen. Most likely, therefore, you just want to make darn sure the correct part of Word has the focus and no modifier keys are pressed beforehand (Ensure Shift, Ctrl and Alt are released).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Aug 28, 2006 9:15 pm

No, no, Marcus is the only one who rocks :)

Strange, it works for me with or without the %'s,

Let>filec[1]=asfdbndfhhnh
MessageModal>%filec[1]%
RunProgram>notepad.exe
Sendtext>filec[1]
Press>Enter
Sendtext>%filec[1]%

To start to address the second question, are you sure the window has focus and the cursor is in the correct location before you sendtext? Also if you paste HTML into a regular word window it'll be a mess. Try notepad instead?

rusty9075
Newbie
Posts: 14
Joined: Sun Aug 27, 2006 4:46 pm

Readfile Help

Post by rusty9075 » Mon Aug 28, 2006 9:21 pm

Ok

So what is the best way to copy a file without opening it and then pasting that text into an internet text box, like ,for example,the one I'm typing in right now. I'm guessing its pretty easy but I'm still pretty new to this.
Thank you,
Rusty9075

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 28, 2006 9:32 pm

I don't really follow what you mean - it's impossible to get the contents of a file without opening it. That's a bit like asking to get inside a house without using the doors or windows!

But as an example, I would do something like:

Code: Select all

Run>Notepad.exe
WaitWindowOpen>notepad*
ReadFile>c:\somefile.txt,txtFileContents
SetFocus>Untitled - Notepad
Send>txtFileContents
Just replace c:\somefile.txt with a valid ASCII text file.

Note - if the file is NOT pure ASCII text then expect utter mayhem and chaos!
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

rusty9075
Newbie
Posts: 14
Joined: Sun Aug 27, 2006 4:46 pm

UPDATE Readfile

Post by rusty9075 » Mon Aug 28, 2006 9:36 pm

Hi Guys

When I tested this out :

readfile>C:\\cafe\flag.txt,file
send text>%file%


in notepad with NO html it did work file.

However, when it had html code in it, the thing goes haywire, in notepad too.

To test this out for yourself, open the source code for any internet page and copy the text and save it as a text file. then run a version of the above program in notepad. Something in the code makes it do weird things.
Am I missing something? Please help if you have an idea how to do this without having problems.... and Me_Again...you DO rock Too!

:)
Rusty9075

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 28, 2006 9:44 pm

Works ok for me. I just took the source of this page and it entered it into Notepad fine.

Another method you could try:

Code: Select all

ReadFile>c:\somefile.txt,txtFileContents
PutClipBoard>txtFileContents
SetFocus>Notepad*
Press CTRL
Send>v
Release CTRL
That should be a bit faster too.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Aug 28, 2006 10:21 pm

I did it too, big file html with javascript, no problem in notepad.

rusty9075
Newbie
Posts: 14
Joined: Sun Aug 27, 2006 4:46 pm

COMBO VARIABLE NOT WORKING

Post by rusty9075 » Mon Aug 28, 2006 11:13 pm

Alright, well I tried the code:

readfile>C:\\cafe\flag.txt,file
send text>%file%

on two different computers (with text file having html code) and they both did weird things. I am using version 7.4 if that makes a difference....BUT the putclipboard method worked PERFECT and was FASTER so I great on using that.


I have one last puzzle if you guys can help. I wanted to use the combo variable with the GCB feature. I used the following code:



let>y=0
repeat>y
let>y=y+1
let>k[%y%]=file


wait>0.2
press ctrl
send text>a
release ctrl
wait>0.2
press ctrl
send text>c
release ctrl

gcb>file

press ctrl
send text>v
release ctrl

send text>here it goes again




until>y=11


send text>%k[3]%



send text>%k[3]% does give a variable result....but if I change "send text" to "send text>%k[9]% if appeared to give the same result as %k[3]%...its almost as if the clipboard doesn't always reset.
(for example I copied and pasted my code into this text box, I then went back and ran this code on MacroScheduler, and the result for "send text>%k[3]%" ended up being my pasted code rather than the predicted variable result.)


Anyway, is there something wrong with my code or is there a better way to do this using the cliboard feature? Please let me know and thank you do much for all the help you've given me

Thank you
Rusty9075

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