CreeTar Posted June 28, 2010 Share Posted June 28, 2010 How come that this code: $a = 0 $b = "empty to prevent" ConsoleWrite($a=$b) will return TRUE, according to the Help "=" is for in-casesensitive string comparison. But obviously it fails here. Or can't i compare a number with a string? The problem is cause by a GetMsg() which is 0, but to prevent a button from working I just gave him a random string, still the comparison hits with TRUE. Link to comment Share on other sites More sharing options...
sahsanu Posted June 28, 2010 Share Posted June 28, 2010 But obviously it fails here. Or can't i compare a number with a string? The problem is cause by a GetMsg() which is 0, but to prevent a button from working I just gave him a random string, still the comparison hits with TRUE. Hello, You can't (or at least you shouldn't ;-)) compare numbers and strings: ;Check this and you will never see the console write $a = 0 $b = "empty to prevent" If IsString($a) Then ConsoleWrite($a=$b) ;And here you will get a beautiful False $a = "" $b = "empty to prevent" If IsString($a) Then ConsoleWrite($a=$b) Cheers, sahsanu Link to comment Share on other sites More sharing options...
CreeTar Posted June 28, 2010 Author Share Posted June 28, 2010 Hello, You can't (or at least you shouldn't ;-)) compare numbers and strings: ;Check this and you will never see the console write $a = 0 $b = "empty to prevent" If IsString($a) Then ConsoleWrite($a=$b) ;And here you will get a beautiful False $a = "" $b = "empty to prevent" If IsString($a) Then ConsoleWrite($a=$b) Cheers, sahsanu but on the other hand $a==$b returns false, how come? since AutoIt is not very type-orientated and variables can't be delcared as int or string this should not happen Link to comment Share on other sites More sharing options...
KaFu Posted June 28, 2010 Share Posted June 28, 2010 expandcollapse popup#cs Language Reference - Operators: "= Tests if two values are equal." Language Reference - Datatypes: "If a string is used as a number, an implicit call to Number() function is done." #ce $a = 0 $b = "empty to prevent" If $a = $b Then ; implicit call to Number($b) = 0 ConsoleWrite("+ True" & @crlf) Else ConsoleWrite("- False" & @crlf) EndIf If Number($a) = Number($b) Then ConsoleWrite("+ True" & @crlf) Else ConsoleWrite("- False" & @crlf) EndIf If string($a) = string($b) Then ConsoleWrite("+ True" & @crlf) Else ConsoleWrite("- False" & @crlf) EndIf #cs Language Reference - Operators: "== Tests if two strings are equal" #ce If $a == $b Then ConsoleWrite("+ True" & @crlf) Else ConsoleWrite("- False" & @crlf) EndIf OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
CreeTar Posted June 28, 2010 Author Share Posted June 28, 2010 cheers for the help, i initialize the variable now with -123 and hope that does it. next time i do an event GUI and not that annoying polling stuff 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