Question regarding IF, Else

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Panorama
Newbie
Posts: 12
Joined: Tue Jul 18, 2006 4:56 am

Question regarding IF, Else

Post by Panorama » Tue Jul 18, 2006 5:09 am

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/

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

Post by Marcus Tettmar » Tue Jul 18, 2006 7:02 am

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?

Panorama
Newbie
Posts: 12
Joined: Tue Jul 18, 2006 4:56 am

Post by Panorama » Tue Jul 18, 2006 1:53 pm

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?

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

Post by Marcus Tettmar » Tue Jul 18, 2006 2:07 pm

Panorama wrote:Press Enter (at line 23)
//Save MP3 File As: Dialog Appears after pressing enter
If this is the case then after pressing enter you want to wait for this dialog to appear:

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?

Panorama
Newbie
Posts: 12
Joined: Tue Jul 18, 2006 4:56 am

Post by Panorama » Tue Jul 18, 2006 2:09 pm

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

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

Post by Marcus Tettmar » Tue Jul 18, 2006 2:12 pm

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?

Panorama
Newbie
Posts: 12
Joined: Tue Jul 18, 2006 4:56 am

Post by Panorama » Thu Jul 20, 2006 4:38 pm

Image
[/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
using SetFocus> command somehow it still does not do any operation when i see Export Mp3 window..should using wait>1 command between window openings

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

Post by Me_again » Thu Jul 20, 2006 5:05 pm

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

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

Post by Marcus Tettmar » Thu Jul 20, 2006 9:12 pm

This is how I would handle it:

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
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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Panorama
Newbie
Posts: 12
Joined: Tue Jul 18, 2006 4:56 am

Post by Panorama » Fri Jul 21, 2006 1:38 pm

It works!!! :) I observe that when "Export MP3" window pops, it stays there for few seconds and then ALT and N commands are executed though in the code there is no wait time OR is it the time required for the code to find, "export Mp3 window"?

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

Post by Marcus Tettmar » Fri Jul 21, 2006 1:44 pm

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?

Panorama
Newbie
Posts: 12
Joined: Tue Jul 18, 2006 4:56 am

Post by Panorama » Fri Jul 21, 2006 2:01 pm

I see it applies to both winodws. if Export Mp3 fails to pop within 10 sec will macro code end?
Image
I need to define a condition if nothing happens.

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

Post by Marcus Tettmar » Fri Jul 21, 2006 2:17 pm

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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Panorama
Newbie
Posts: 12
Joined: Tue Jul 18, 2006 4:56 am

Post by Panorama » Fri Jul 21, 2006 3:17 pm

thank you...i would address my progress and some problems thanks.

Panorama
Newbie
Posts: 12
Joined: Tue Jul 18, 2006 4:56 am

Post by Panorama » Fri Jul 21, 2006 4:21 pm

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
Iam unable to understand the correct way to do this. I have a dialog box with two buttons, test and cancel...I am able to cancel it..and nothing happens after that. but something strange is going on when I press test the program loads but few things are not happening the way they should ( ican give all details on that). ? need a suggestion

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