If statement problems

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
BlackCat
Newbie
Posts: 13
Joined: Mon Dec 20, 2010 12:32 am

If statement problems

Post by BlackCat » Thu Jan 13, 2011 2:25 am

I want to check that I have selected a resolution in my dialog before I close it. The resolutions in the drop down box change based on a check box selection. The resolutions are listed in the code below. The Else to those resolutions is either "Select Resolution" or "Must Select a Device from Above". I was hoping to use the "If" statement below to combine the resolution check into one Sub-Routine, but I am unsure how/if I can have multiple items in the IF line like below. I tried the use of "OR" based on this post: http://www.mjtnet.com/usergroup/viewtopic.php?t=6646
Thanks for any help :D

Code: Select all

//Dialog Box verifications before close on OK: Resolution
SRT>DoVerifyAndClose_Resolution
    GetDialogProperty>Dialog1,DDB_Resolution,Text,varResolution_Check
    If>varResolution_Check={(480x270) OR (426x320) OR (640x360) OR (640x480) OR (800x450) OR (800x600) OR (1024x576) OR (1024x768) OR (720x408) OR (856x480) OR (960x720) OR (1280x720)}
        Let>Validate=True
        CloseDialog>Dialog1
    Else
        MessageModal>Please Select a Resolution
    
    Endif
END>DoVerifyAndClose_Resolution

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

Post by JRL » Thu Jan 13, 2011 5:31 am

Code: Select all

SRT>DoVerifyAndClose_Resolution
    GetDialogProperty>Dialog1,DDB_Resolution,Text,varResolution_Check
    If>{(%varResolution_Check%="480x270")OR(%varResolution_Check%="426x320")OR(%varResolution_Check%="640x360")OR(%varResolution_Check%="640x480")OR(%varResolution_Check%="800x450")OR(%varResolution_Check%="800x600")OR(%varResolution_Check%="1024x576")OR(%varResolution_Check%="1024x768")OR(%varResolution_Check%="720x408")OR(%varResolution_Check%="856x480")OR(%varResolution_Check%="960x720")OR(%varResolution_Check%="1280x720")}
        Let>Validate=True
        CloseDialog>Dialog1
    Else
        MessageModal>Please Select a Resolution
    
    Endif
END>DoVerifyAndClose_Resolution

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

Post by Marcus Tettmar » Thu Jan 13, 2011 8:25 am

If this is a combo box and you just want to make sure something - anything - has been selected, there's no need to do an OR check for every conceivable choice ... just check that ItemIndex is greater than -1. If ItemIndex is -1 then nothing is selected. 0 is the first item in the list, so if ItemIndex is greater than -1 the user has selected something:

GetDialogProperty>Dialog1,DDB_Resolution,ItemIndex,varItemIndex
If>varItemIndex>-1
...
...
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

BlackCat
Newbie
Posts: 13
Joined: Mon Dec 20, 2010 12:32 am

Post by BlackCat » Fri Jan 14, 2011 12:05 am

JRL wrote:

Code: Select all

SRT>DoVerifyAndClose_Resolution
    GetDialogProperty>Dialog1,DDB_Resolution,Text,varResolution_Check
    If>{(%varResolution_Check%="480x270")OR(%varResolution_Check%="426x320")OR(%varResolution_Check%="640x360")OR(%varResolution_Check%="640x480")OR(%varResolution_Check%="800x450")OR(%varResolution_Check%="800x600")OR(%varResolution_Check%="1024x576")OR(%varResolution_Check%="1024x768")OR(%varResolution_Check%="720x408")OR(%varResolution_Check%="856x480")OR(%varResolution_Check%="960x720")OR(%varResolution_Check%="1280x720")}
        Let>Validate=True
        CloseDialog>Dialog1
    Else
        MessageModal>Please Select a Resolution
    
    Endif
END>DoVerifyAndClose_Resolution
Thanks, JRL that worked. Is there some place in the help material or else where that explains the difference between the {} and () brackets and in what context they are used? I was trying to find some info on basic symbols and in what context they are used, but was having a hard time.

mtettmar wrote:If this is a combo box and you just want to make sure something - anything - has been selected, there's no need to do an OR check for every conceivable choice ... just check that ItemIndex is greater than -1. If ItemIndex is -1 then nothing is selected. 0 is the first item in the list, so if ItemIndex is greater than -1 the user has selected something:

GetDialogProperty>Dialog1,DDB_Resolution,ItemIndex,varItemIndex
If>varItemIndex>-1
...
...
Thanks, Marcus I didn't think of that. At first, I thought the command wouldn't work because "Must Select Device" is the default text before a device is chosen and is the only item in the drop-down. However, I have a check for selecting the device, so the resolution IF statement is not affected by that text. Also, once a device is selected the default text shows "Select a Resolution", but only the resolutions show in the drop-down when it's expanded. Therefore, the command worked as desired. Thank you.

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

Post by Marcus Tettmar » Fri Jan 14, 2011 10:02 am

Thanks, JRL that worked. Is there some place in the help material or else where that explains the difference between the {} and () brackets and in what context they are used? I was trying to find some info on basic symbols and in what context they are used, but was having a hard time.
http://www.mjtnet.com/OnlineHelp/complexexpressions.htm
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

BlackCat
Newbie
Posts: 13
Joined: Mon Dec 20, 2010 12:32 am

Post by BlackCat » Fri Jan 14, 2011 3:46 pm

Thanks I wasn't sure what to look under.

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