IvanCodin Posted May 27, 2010 Share Posted May 27, 2010 I am using the following syntax in my if statement. It does not error when I run the syntax checker in Scite but it doesn't appear to work as I expect it to. Am I using the correct syntax?. Below is a snippet from my script that shows what I am trying to do. If $Type = "2" or "3" or "4" or "5" Then FileWrite($oputfile, "ip address" & @CRLF) FileWrite($oputfile, @CRLF) Else MsgBox(0, "Info", "System type is not standard") EndIf Me Link to comment Share on other sites More sharing options...
Bowmore Posted May 27, 2010 Share Posted May 27, 2010 It should be like this If $Type = "2" or $Type = "3" or $Type = "4" or $Type = "5" Then FileWrite($oputfile, "ip address" & @CRLF) FileWrite($oputfile, @CRLF) Else MsgBox(0, "Info", "System type is not standard") EndIf "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
IvanCodin Posted May 27, 2010 Author Share Posted May 27, 2010 Thanks! I am suprised Scite didn't catch it!! I am afraid to ask but ....... I looked in the help file and didn't see an example. Was it there? Me Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 27, 2010 Share Posted May 27, 2010 Change If $Type = "2" or "3" or "4" or "5" Then to If $Type = "2" Or $Type = "3" Or $Type = "4" Or $Type = "5" Then.Note the caps aren't really necessary, I couldn't help it though.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Developers Jos Posted May 27, 2010 Developers Share Posted May 27, 2010 Thanks! I am suprised Scite didn't catch it!!The syntax wasn't wrong , just your logic. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
IvanCodin Posted May 27, 2010 Author Share Posted May 27, 2010 Yep I figured that out after I put it in the script and it ran successfully!! As usual the program is smarter than me :-) One last question are global variables case sensative in Autoit? I would take it from the comment they arent't. Me Link to comment Share on other sites More sharing options...
jchd Posted May 27, 2010 Share Posted May 27, 2010 Thanks! I am suprised Scite didn't catch it!!I am afraid to ask but ....... I looked in the help file and didn't see an example. Was it there?The checker won't catch this because it is a valid syntax (besides it doesn't behave as you were expecting).If <condition> Then ...Now $Type = "2" Or "3" is a perfectly valid <condition>. It boils down to evaluating $Type = "2" test as a boolean (this works as you whish) and then "3" as a boolean. When you open the helpfile >> Language Reference >> DataTypes, you read:The other way around however is different. When you use string comparisons with Boolean values, the following rules apply:Only an empty string ("") will be a Boolean falseAny other string values (including a string equal "0") will be a Boolean trueThus "3" will evaluate as Boolean True (and the counpound condition will stop there due to Or short-circuit).Hope this is clearer now. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jchd Posted May 27, 2010 Share Posted May 27, 2010 No keyword or user created object (variable, constant, enumeration, function) is case sensitive in AutoIt, either global, local or static. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 27, 2010 Share Posted May 27, 2010 If you're referring to the Or's I capitalized, they're not Global variables, they are Logical Operators, and they aren't case sensitive. In the docs, they're all caps, but they'll work either lowercase, all uppercase, or the first letter capitalized. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Tvern Posted May 28, 2010 Share Posted May 28, 2010 If you are checking one variable to many different values I reccomend using a switch statement like this: $Type = 1 ;Set the value of $Type here Switch String($Type) ;Autoit should make $Type a string when compared to one, but just to be sure we'll make it one, You could also make it a number and compare to numbers. Case "2","3","4","5" ConsoleWrite("$Type = 2, or 3, or 4, or 5" & @CRLF) Case "1" ConsoleWrite("$Type = 1" & @CRLF) Case Else ConsoleWrite("$Type = not 1, or 2, or 3, or 4, or 5" & @CRLF) EndSwitch Link to comment Share on other sites More sharing options...
jchd Posted May 28, 2010 Share Posted May 28, 2010 Tvern,;Autoit should make $Type a string when compared to oneNo, it's more involved.In If 1 = $var Then ... AutoIt does If 1 = Number($var) Then ...But in If 1 == $var Then ... AutoIt does If String(1) == String($var) Then ... This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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