Muhammad_Awais_Sharif Posted September 27, 2016 Posted September 27, 2016 Why this code does not work ? $tmp = "1111" If StringIsDigit($tmp) == True Then MsgBox(0,"",StringIsDigit($tmp) == "1") EndIf and this one works $tmp = "1111" If StringIsDigit($tmp) == "1" Then MsgBox(0,"",StringIsDigit($tmp) == "1") EndIf
AndyG Posted September 27, 2016 Posted September 27, 2016 https://www.autoitscript.com/autoit3/docs/functions/StringIsDigit.htm Reading the help helps
Muhammad_Awais_Sharif Posted September 27, 2016 Author Posted September 27, 2016 1 minute ago, AndyG said: https://www.autoitscript.com/autoit3/docs/functions/StringIsDigit.htm Reading the help helps Success: 1 does not mean True ? what is wrong in comparing with true ?
orbs Posted September 27, 2016 Posted September 27, 2016 the reason is you using the == operator, which is dedicated to case-sensitive string comparison, for boolean and numeric comparison, not cool. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
AndyG Posted September 27, 2016 Posted September 27, 2016 (edited) "1" is a string, and 1 is a number, TRUE is boolean.... you should not compare a string with a number ! The result of a comparison is TRUE or FALSE (1 = "1") is (should be) FALSE //EDIT (but NOT in AutoIt because of datatype "variant"?! ) so (1="1") in AutoIt is TRUE (1 = TRUE) is TRUE Edited September 27, 2016 by AndyG
Muhammad_Awais_Sharif Posted September 27, 2016 Author Posted September 27, 2016 okay problem is that in C++ or java single = operator assign value. So that's why i was using double equal i got it ty
jchd Posted September 27, 2016 Posted September 27, 2016 (edited) More precisely, when you write: If StringIsDigit($tmp) == True Then the interpretor understands: If '1' == 'True' Then because == forces the conversion of its operands to strings and StringIsDigit returns the integer 0 or 1 (1 in your case), while the string 'True' stays by itself. Since the == comparison is over verbatim (case-insensitive) strings, it clearly fails. The lazy, simple and robust way to code that condition is: If StringIsDigit($tmp) Then Edited September 27, 2016 by jchd Muhammad_Awais_Sharif and Skysnake 2 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)
bloopie Posted September 27, 2016 Posted September 27, 2016 (edited) 3 hours ago, jchd said: The lazy, simple and robust way to code that condition is: If StringIsDigit($tmp) Then Indeed! @Muhammad_Awais_Sharif ...Use a single equals (=) for comarison, as well as assignment in AutoIt for cases like this...or just say "If X Then" (whenever X is true..."Then" will execute) (...It took me a few minutes to wrap my head around the 'single equals comparison' as well, so you're in good company!) bloopie Edited September 27, 2016 by bloopie clarification Muhammad_Awais_Sharif 1 Malware Response Instructor @ BC
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