leuce Posted April 25, 2010 Share Posted April 25, 2010 G'day everyoneThe help file for "If...Then" states that:"The expression can contain the boolean operators of AND, OR, and NOT as well as the logical operators <, <=, >, >=, =, ==, and <> grouped with parentheses as needed."...but it doesn't give examples of how this could be accomplished. The following does not work for me:$format = InputBox ( "Which image format do you want?", "Which image format do you want? Valid options are: JPG, BMP, GIF, PNG and TIF.", "JPG") If [something] Then MsgBox (0, "", "Sorry, that is not valid format.", 0) Else MsgBox (0, "", "Sorry, the programmer screwed up...", 0) EndIfI've tried the following [something]:($format NOT "JPG") AND ($format NOT "BMP") AND ($format NOT "GIF") AND ($format NOT "PNG") AND ($format NOT "TIF") $format (NOT "JPG") AND (NOT "BMP") AND (NOT "GIF") AND (NOT "PNG") AND (NOT "TIF") $format = (NOT "JPG") AND (NOT "BMP") AND (NOT "GIF") AND (NOT "PNG") AND (NOT "TIF") $format = (NOT "JPG" AND NOT "BMP" AND NOT "GIF" AND NOT "PNG" AND NOT "TIF")The first two throws me an error. The second two tells me that the programmer screwed up. What I want is to be dol that the format is invalid (see Autoit code above). Obviously I'm doing something wrong here. Can anyone tell me what the correct syntax would be?ThanksSamuel AndrewSchultz 1 Link to comment Share on other sites More sharing options...
Tvern Posted April 25, 2010 Share Posted April 25, 2010 (edited) Well I think the section between parentheses needs to be a valid equation like this:($format = NOT "JPG")orNOT ($format = "BMP")the above is incorrect, read PsaltyDS' post for the real functionality.You can also use them the way you would in math, to evaluate the formula inside the parentheses before the rest of the formula like this:2*5+5 = 152*(5+5) = 20For your script I would advise using a Switch statement like this:$format = InputBox ( "Which image format do you want?", "Which image format do you want? Valid options are: JPG, BMP, GIF, PNG and TIF.", "JPG") Switch $format Case "JPG", "BMP", "GIF", "PNG", "TIF" ConsoleWrite("Case 1 is true" & @CRLF) Case Else ConsoleWrite("Case 2 is true" & @CRLF) EndSwitchedit and re-edit:removed false information Edited April 26, 2010 by Tvern AndrewSchultz 1 Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 26, 2010 Share Posted April 26, 2010 (edited) As Tvern posted, Switch/Case/EndSwitch is a much better choice for the function. But to address the compare logic: The NOT operator is simple boolean negation. And NOT is first operator in the order of operations, so be careful with it. ($format = NOT "JPG") will first perform (NOT "JPG") because of order of operations. For strings, if the string is not empty, it evaluates as TRUE, so "JPG" evaluates as Boolean TRUE, and (NOT "JPG") evaluates as FALSE. The actual contents of the string are not evaluated, so (NOT "FALSE") still evaluates as Boolean FALSE because the string "FALSE" is not empty. The result is $format = FALSE for every string except and empty one. This version suffers from the same problem: NOT ($format = "BMP") The correct test would be: If $format <> "BMP" Then So, if for some reason you couldn't use Switch/Case/EndSwitch, the full test would be: If ($format <> "JPG") AND ($format <> "BMP") AND ($format <> "GIF") AND ($format <> "PNG") AND ($format <> "TIF") Then ; Not valid input Else ; Valid input EndIf Or, put the other way around: If ($format = "JPG") OR ($format = "BMP") OR ($format = "GIF") OR ($format = "PNG") OR ($format "TIF") Then ; Valid input Else ; Not valid input EndIf Edited April 26, 2010 by PsaltyDS AndrewSchultz 1 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now