JohnOne Posted February 7, 2012 Share Posted February 7, 2012 (edited) I apologise for this question as I'm sure I have seen it before but have simply forgotten. I had it in my head that only an empty string was equal to 0 Also that to test a case string is == But I'm unsure if this behaviour is normal. $string = 'string' If $string = 0 Then MsgBox(0,0,$string) EndIf It results in a message box, I cannot remember why. Can someone refresh my memory, as it is difficult to search. Edited February 7, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 7, 2012 Moderators Share Posted February 7, 2012 JohnOne,In a Boolean comparison, an empty string converts to False, if it has any content then it converts to True. For numbers 0 = False, anything else = True.Using == forces both sides of a comparison into string type and makes a case-sensitive comparison.It is best to use the same type on both sides of a comparison - AutoIt does its best to guess what you want but it is best to make it explicit. I am not sure why you get a MsgBox from the code you posted - I would not have expected one at first glance. I can only imagine that there is some type changing going on behind the scenes and the result is not what you expect. But as the 2 sides of the comparison are currently different types, my advice above is relevant - use the same type for both: $string = "string" If $string = "" Then MsgBox(0, 0, "empty string") Else MsgBox(0, 0, $string) EndIfThat works as I expect in both cases. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Shaggi Posted February 7, 2012 Share Posted February 7, 2012 Only an empty string ("") will be a Boolean false Any other string values (including a string equal "0") will be a Boolean true Seems to be a bug, especially since case sensitive comparison yields expected results. however, in strictly boolean tests: If $string = false Then or If not $string Then works as expected. In any case, you should never compare strings to numbers, its undefined in most cases Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
JohnOne Posted February 7, 2012 Author Share Posted February 7, 2012 Cheers, Just that I don't recall this behaviour in previous versions see. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
trancexx Posted February 7, 2012 Share Posted February 7, 2012 I apologise for this question as I'm sure I have seen it before but have simply forgotten. I had it in my head that only an empty string was equal to 0 Also that to test a case string is == But I'm unsure if this behaviour is normal. $string = 'string' If $string = 0 Then MsgBox(0,0,$string) EndIf It results in a message box, I cannot remember why. Can someone refresh my memory, as it is difficult to search. Because numeric value of string 'string' is 0. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 7, 2012 Moderators Share Posted February 7, 2012 trancexx, Just out of interest, and certainly not because I intend ever using it, is there a simple logic behind AutoIt's type use for comparisons? I was thinking along the lines of numeric 0 being converted to the literal string "0", but you indicate that it was the string being converted to a number. Which side gets the priority in a mixed type comparison? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
trancexx Posted February 7, 2012 Share Posted February 7, 2012 trancexx, Just out of interest, and certainly not because I intend ever using it, is there a simple logic behind AutoIt's type use for comparisons? I was thinking along the lines of numeric 0 being converted to the literal string "0", but you indicate that it was the string being converted to a number. Which side gets the priority in a mixed type comparison? M23 Side doesn't matter, operator does. If you do "==" then it's all about strings, but if you use "=" then AutoIt uses table to determine how to do a job. Don't worry, it does it in most logical way. $string = '1string' If $string = 1 Then MsgBox(0, 0, $string) EndIf ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 7, 2012 Moderators Share Posted February 7, 2012 trancexx,it does it in most logical wayBased on whose definition of logic, I wonder? Thanks for responding. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Beege Posted February 7, 2012 Share Posted February 7, 2012 I tried explaining why this happens some time back. In autoit, if a string is a number AND it is used with or compared to a number, a implicit call to Number() function will be made on the string. If the string doesn't contain a valid number, it will be assumed to equal to 0. Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator 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