Question regarding IF, Else
Moderators: Dorian (MJT support), JRL
Question regarding IF, Else
First of all I am new to Macro. I manually test 20 computers with 4 types softwares (you all know them, MS WORD, Audacity, WMA, Photostory).
This is my script going good till line 25
message>This Automated Software is desgined to test MS Word, Audacity, Photostory, Windowds Media Player and Adobe Acrobat Created for ESL Dept
WaitWindowClosed>Macro Scheduler Message
Let>WW_timeout=99999
If>WW_RESULT=FALSE,Endit
Run Program>c:\Program Files\Audacity\Audacity.exe
wait>2
Send Character/Text>r
test1.mp3
wait>1
Send Character/Text>s
wait>1
Press ALT
Send Character/text>f
Release ALT
Press Down
Press Down
Press Down
Press Down
Press Down
Press Down
Press Down
Press Down
Press Enter
Send Character/Text>test1.mp3
Press Enter Edit the ID3 tags for the MP3 file
Wat comes after line 25 is two things: A message box with title "Edit the ID3 tags for the MP3 file" having bunch of options, if you press enter the program saves a audio file. IF this Dialogue box doesnot appear then other message appears which is "Export MP3" has two options Yes and NO.
If there is a "export Mp3 " message box i want to click NO, exit the program. I tried lot of times to get this done but no luck. If you guys can suggest anything..Thank you
Some tips are welcomed/
This is my script going good till line 25
message>This Automated Software is desgined to test MS Word, Audacity, Photostory, Windowds Media Player and Adobe Acrobat Created for ESL Dept
WaitWindowClosed>Macro Scheduler Message
Let>WW_timeout=99999
If>WW_RESULT=FALSE,Endit
Run Program>c:\Program Files\Audacity\Audacity.exe
wait>2
Send Character/Text>r
test1.mp3
wait>1
Send Character/Text>s
wait>1
Press ALT
Send Character/text>f
Release ALT
Press Down
Press Down
Press Down
Press Down
Press Down
Press Down
Press Down
Press Down
Press Enter
Send Character/Text>test1.mp3
Press Enter Edit the ID3 tags for the MP3 file
Wat comes after line 25 is two things: A message box with title "Edit the ID3 tags for the MP3 file" having bunch of options, if you press enter the program saves a audio file. IF this Dialogue box doesnot appear then other message appears which is "Export MP3" has two options Yes and NO.
If there is a "export Mp3 " message box i want to click NO, exit the program. I tried lot of times to get this done but no luck. If you guys can suggest anything..Thank you
Some tips are welcomed/
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
You want something like:
Code: Select all
WaitWindowChanged
IfWindowOpen>Edit the ID3 tags for the MP3 file
...
... do whatever
...
Else
IfWindowOpen>Export MP3
//Press No
Press ALT
Send>n
Release ALT
Endif
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Press Enter (at line 23)
//Save MP3 File As: Dialog Appears after pressing enter
Send Character/Text>test1.mp3
Press Enter
//After pressing enter either, "Edit the ID3 tags for the MP3 file OR Export MP3" opens
WaitWindowChanged>Save MP3 File As:
IfwindowOpen>Edit the ID3 tags for the MP3 file
Press enter
Else
IfwindowOpen>Export MP3
Press ALT
Send>n
Release ALT
endif
endif
This code does not passes the "export MP3" message window, it does not press Alt or send>n. can you point out where i am going wrong?
//Save MP3 File As: Dialog Appears after pressing enter
Send Character/Text>test1.mp3
Press Enter
//After pressing enter either, "Edit the ID3 tags for the MP3 file OR Export MP3" opens
WaitWindowChanged>Save MP3 File As:
IfwindowOpen>Edit the ID3 tags for the MP3 file
Press enter
Else
IfwindowOpen>Export MP3
Press ALT
Send>n
Release ALT
endif
endif
This code does not passes the "export MP3" message window, it does not press Alt or send>n. can you point out where i am going wrong?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
If this is the case then after pressing enter you want to wait for this dialog to appear:Panorama wrote:Press Enter (at line 23)
//Save MP3 File As: Dialog Appears after pressing enter
23: Press Enter
24: WaitWindowOpen>Save MP3 File As
25: SetFocus>Save MP3 File As
etc
Bear in mind I am working in the dark here as I only have your descriptions to go from. It may help to see screen shots.
Have you read "Scripting Windows for Beginners" in the help file? Also check out this article:
http://www.mjtnet.com/blog/2006/01/17/h ... on-script/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Press Enter
//Save MP3 File As: Dialog Appears after pressing enter
Send Character/Text>test1.mp3
Press Enter
//After pressing enter either, "Edit the ID3 tags for the MP3 file OR Export MP3" opens
WaitWindowOpen>Edit the ID3 tags for the MP3 file
let>WW_timeout=2
If>WW_Result=True
Press enter
Else
WaitWindowOpen>Export MP3
Let>ww_timeout=2
If>ww_result=true
Press enter
else
Press ALT
send>F4
Release ALT
endif
endif
I even tried doing this but does not work
//Save MP3 File As: Dialog Appears after pressing enter
Send Character/Text>test1.mp3
Press Enter
//After pressing enter either, "Edit the ID3 tags for the MP3 file OR Export MP3" opens
WaitWindowOpen>Edit the ID3 tags for the MP3 file
let>WW_timeout=2
If>WW_Result=True
Press enter
Else
WaitWindowOpen>Export MP3
Let>ww_timeout=2
If>ww_result=true
Press enter
else
Press ALT
send>F4
Release ALT
endif
endif
I even tried doing this but does not work
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
You are not waiting for the dialog to appear before sending keystrokes to it. Please see my previous reply. Please read the getting started guide - it will explain these key concepts. Always use WaitWindowOpen after an action causes a new window to appear to ensure the window is ready for the next set of keystrokes and make a habit of using SetFocus before sending keystrokes to ensure the correct window has the focus.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
[/img]
Code: Select all
message>This Automated Software is desgined to test MS Word, Audacity, Photostory, Windowds Media Player and Adobe Acrobat Created for ESL Dept
WaitWindowClosed>Macro Scheduler Message
Let>WW_timeout=99999
If>WW_RESULT=FALSE,Endit
Run Program>c:\Program Files\Audacity\Audacity.exe
wait>2
Send Character/Text>r
wait>1
Send Character/Text>s
wait>1
Press ALT
Send Character/text>f
Release ALT
//going down through the file menu to "Export as MP3"
Press Down
Press Down
Press Down
Press Down
Press Down
Press Down
Press Down
Press Down
Press Enter
//Save MP3 File As: Dialog Appears after p ressing enter
WaitwindowOpen>Save MP3 File As:
Setfocus>Save Mp3 File As:*
Send Character/Text>test1.mp3
Press Enter
//After pressing enter either, "Edit the ID3 tags for the MP3 file OR Export MP3" opens
WaitWindowOpen>Edit the ID3 tags for the MP3 file
SetFocus>Edit the ID3 tags for the MP3 file*
IfWindowOpen>Edit the ID3 tags for the MP3 file
Press enter
Else
WaitwindowOpen>Export MP3
SetFocus>Export MP3*
Press ALT
Send>n
Release ALT
endif
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
If you can get either the "Edit the ID3 tags for the MP3 file" window OR the "Export MP3" then you can't use
WaitWindowOpen>Edit the ID3 tags for the MP3 file
because the macro will just stall if "Export MP3" opens instead.
You would do better to structure it something like:
Wait>sometime
IfWindowOpen>Edit the ID3 tags for the MP3 file,dothis
IfWindowOpen>Export MP3,dothat
WaitWindowOpen>Edit the ID3 tags for the MP3 file
because the macro will just stall if "Export MP3" opens instead.
You would do better to structure it something like:
Wait>sometime
IfWindowOpen>Edit the ID3 tags for the MP3 file,dothis
IfWindowOpen>Export MP3,dothat
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
This is how I would handle it:
What this does is use a timeout for WaitWindowOpen. It waits for "Edit the ID3 tags for the MP3 file". We then see if we timed out or not. If we did timeout then we see if the "Export MP3" window is open. If so we send ALT-n. If we did NOT time out then the "Edit the ID3 tags for the MP3 file" window DID appear, so we do what we need to do to that.
Code: Select all
WaitWindowOpen>Save MP3 File As:
SetFocus>Save Mp3 File As:*
Send Character/Text>test1.mp3
Press Enter
Let>WW_TIMEOUT=10
WaitWindowOpen>Edit the ID3 tags for the MP3 file
If>WW_RESULT=FALSE
IfWindowOpen>Export MP3
//The DLL issue window appeared ..
SetFocus>Export MP3
Press ALT
Send>n
Release ALT
Endif
else
//"Edit the ID3 tags for the MP3 file" appeared ok,
SetFocus>Edit the ID3 tags for the MP3 file
Press Enter
endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Yes, if you look at my code and re-read my explanation you will see that it looks for the other window first and TIMES OUT after 10 seconds if it DOES NOT find it. So IF THE "Export MP3" window appears there will be a 10 second delay before it is cancelled.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Not sure what you mean. If "Edit the ID3 tags for the MP3 file" appears there is no delay. If "Export MP3" appears there will be a 10 second delay.
Let me try to explain the code again:
Let>WW_TIMEOUT=10
WaitWindowOpen>Edit the ID3 tags for the MP3 file
In English: Wait for the window entitled "Edit the ID3 tags for the MP3 file" to appear, OR 10 seconds, whichever comes first
If>WW_RESULT=FALSE
In English: If we timed out - in other words if 10 seconds elapsed BEFORE the window appeared then ...
IfWindowOpen>Export MP3
If "Export MP3" is open then ...
//The DLL issue window appeared ..
SetFocus>Export MP3
Press ALT
Send>n
Release ALT
Press ALT-n on "Export MP3"
Endif
else
//"Edit the ID3 tags for the MP3 file" appeared ok,
SetFocus>Edit the ID3 tags for the MP3 file
Press Enter
Otherwise (10 seconds did NOT elapse before "Edit the ID3 tags for the MP3 file" appeared), focus "Edit the ID3 tags for the MP3 file" and press Enter
There is nothing to say the macro will end if "Export MP3" fails to pop up within 10 seconds. However, the code I gave doesn't account for the situation where NEITHER window appears .... You can add an ELSE condition to the IfWindowOpen>Export MP3 line for that.
Let me try to explain the code again:
Let>WW_TIMEOUT=10
WaitWindowOpen>Edit the ID3 tags for the MP3 file
In English: Wait for the window entitled "Edit the ID3 tags for the MP3 file" to appear, OR 10 seconds, whichever comes first
If>WW_RESULT=FALSE
In English: If we timed out - in other words if 10 seconds elapsed BEFORE the window appeared then ...
IfWindowOpen>Export MP3
If "Export MP3" is open then ...
//The DLL issue window appeared ..
SetFocus>Export MP3
Press ALT
Send>n
Release ALT
Press ALT-n on "Export MP3"
Endif
else
//"Edit the ID3 tags for the MP3 file" appeared ok,
SetFocus>Edit the ID3 tags for the MP3 file
Press Enter
Otherwise (10 seconds did NOT elapse before "Edit the ID3 tags for the MP3 file" appeared), focus "Edit the ID3 tags for the MP3 file" and press Enter
There is nothing to say the macro will end if "Export MP3" fails to pop up within 10 seconds. However, the code I gave doesn't account for the situation where NEITHER window appears .... You can add an ELSE condition to the IfWindowOpen>Export MP3 line for that.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Code: Select all
Dialog>dialog1
Caption=TESTER
Width=445
Height=119
Top=273
Left=1422
Max=0
Min=0
Close=1
Resize=1
Label=This is an automated error checker to test programs.,88,8,true
Label=Created for ESL Department by "MY NAME",104,24,true
Button=Test,136,48,75,25,1
Button=Exit,216,48,75,25,2
EndDialog>dialog1
Show>dialog1
label>actionloop
GetdialogAction>dialog1,r
if>r=2,Cancel
if>r=1,Tester
Goto>actionloop
Label>exit
SRT>Cancel
Closedialog>dialog1
End>Cancel
SRT>Tester
Closedialog>dialog1
Wait>1
Run Program>c:\Program Files\Audacity\Audacity.exe
wait>2
Setfocus>Audacity*
..
..
bunch of code
..
..
END>TESTER