laurin1 Posted May 26, 2011 Share Posted May 26, 2011 Why in AutoIt does this not work? $bTest = False does not equal false, it equals true when tested as part of an If statement. $bTest = False If $bTest Then MsgBox(0, '', 'WILL SHOW THIS BOX') EndIf It works in PHP and other scripting language (that are loosely typed, anyway.) For AutoIt, I have to do this to test for False $bTest = False If $bTest <> False Then MsgBox(0, '', 'WILL NOT SHOW THIS BOX') EndIf Now, if I set $bTest to 0 it works...so, why doesn't False == 0 $bTest = 0 If $bTest Then MsgBox(0, '', 'WILL NOT SHOW THIS BOX')) EndIf Keith Davis MCSA, ZCE, A+, N+ http://www.laurinkeithdavis.com Link to comment Share on other sites More sharing options...
laurin1 Posted May 26, 2011 Author Share Posted May 26, 2011 Oh, never mind. I was testing 'False', not False. Doh! Keith Davis MCSA, ZCE, A+, N+ http://www.laurinkeithdavis.com Link to comment Share on other sites More sharing options...
Developers Jos Posted May 26, 2011 Developers Share Posted May 26, 2011 Why in AutoIt does this not work? $bTest = False does not equal false, it equals true when tested as part of an If statement. $bTest = False If $bTest Then MsgBox(0, '', 'WILL SHOW THIS BOX') EndIf No msgbox is shown for me with this code. ...and a msgbox is shown for: $bTest = True If $bTest Then MsgBox(0, '', 'WILL SHOW THIS BOX') EndIf 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...
Developers Jos Posted May 26, 2011 Developers Share Posted May 26, 2011 Oh, never mind. I was testing 'False', not False. Doh!aahh... you test with 'false' in your editor but you change that when you post the question... Does that mean you are retyping the code when posting? 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...
laurin1 Posted May 26, 2011 Author Share Posted May 26, 2011 aahh... you test with 'false' in your editor but you change that when you post the question... Does that mean you are retyping the code when posting?No, I was pulling the value from an .ini file, which I realized after I posted this question. Keith Davis MCSA, ZCE, A+, N+ http://www.laurinkeithdavis.com Link to comment Share on other sites More sharing options...
Developers Jos Posted May 26, 2011 Developers Share Posted May 26, 2011 No, I was pulling the value from an .ini file, which I realized after I posted this question.k.. that would do it too 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...
laurin1 Posted May 26, 2011 Author Share Posted May 26, 2011 k.. that would do it too Sorry for the confusion, but on further review I was incorrect about checking 'False', in fact it appears that I am checking False after all and it does not work. Now, if I set $bTest to False ($bTest = False), it works, but in this case I'm doing this: $bSharedINIFile = IniRead($MASTERINIFILE, $SCRIPTNAME, 'SharedINIFile', False) And then if I do this MsgBox(0, '', $bSharedINIFile == False) I get True However, in this statement, the If evaluates to true If $bSharedINIFile Then If FileExists($SHAREDINIFILEPATH & '\' & $sIniFileNameToLookFor) Then $sIniFileName = $SHAREDINIFILEPATH & '\' & $sIniFileNameToLookFor Return True EndIf Else Keith Davis MCSA, ZCE, A+, N+ http://www.laurinkeithdavis.com Link to comment Share on other sites More sharing options...
laurin1 Posted May 26, 2011 Author Share Posted May 26, 2011 In other words, I add this If $bSharedINIFile == False Then $bSharedINIFile = False EndIf The If evaluates to false, but otherwie, it evaluates to true.....is that a bug? Keith Davis MCSA, ZCE, A+, N+ http://www.laurinkeithdavis.com Link to comment Share on other sites More sharing options...
Developers Jos Posted May 26, 2011 Developers Share Posted May 26, 2011 Can you make a simple script to explain your issue because you are confusing me. Also realise the following: - IniRead() returns a string - comparing with == means: Tests if two strings are equal. Anyway... make a short and sweet script that we can run and demonstrates your issue/question. Jos 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...
ProgAndy Posted May 26, 2011 Share Posted May 26, 2011 The == operator forces a case sensitive string comparison, so the keyword false is converted to the string "False" before the comparison. When reading boolean values from an ini-file, I use this function to convert the string: Func _Bool($vVal) ; Author: ProgAndy If IsBool($vVal) Then Return $vVal = True If IsNumber($vVal) Or StringIsDigit($vVal) Or StringIsFloat($vVal) Then Return Number($vVal) <> 0 Switch $vVal Case "y", "yes", "true", "ja", "wahr", "j" Return True Case Else Return False EndSwitch EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Bowmore Posted May 26, 2011 Share Posted May 26, 2011 The place your script is going wrong is with ReadIni(). ReadIni() always returns a string so you need to test the values as a string like this. $bSharedINIFile = IniRead($MASTERINIFILE, $SCRIPTNAME, 'SharedINIFile', "False") If $bSharedINIFile = "False" Then MsgBox(0, '', '$bSharedINIFile = "False"') Endif If $bSharedINIFile = "True" Then MsgBox(0, '', '$bSharedINIFile = "True"') 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...
laurin1 Posted May 26, 2011 Author Share Posted May 26, 2011 The place your script is going wrong is with ReadIni(). ReadIni() always returns a string so you need to test the values as a string like this. $bSharedINIFile = IniRead($MASTERINIFILE, $SCRIPTNAME, 'SharedINIFile', "False") If $bSharedINIFile = "False" Then MsgBox(0, '', '$bSharedINIFile = "False"') Endif If $bSharedINIFile = "True" Then MsgBox(0, '', '$bSharedINIFile = "True"') EndIf Ok, that is what is throwing me...I realize that if I return an actual value from the INI file of "False", that will be a string, but I mine was failing on the default value of False. That was what was confusing me. Keith Davis MCSA, ZCE, A+, N+ http://www.laurinkeithdavis.com Link to comment Share on other sites More sharing options...
ProgAndy Posted May 26, 2011 Share Posted May 26, 2011 Strings are considered as true when they are not empty. (equal to if Stringlen($string) > 0 then) I don't know why, bit this is how it works. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
laurin1 Posted May 26, 2011 Author Share Posted May 26, 2011 Strings are considered as true when they are not empty. (equal to if Stringlen($string) > 0 then) I don't know why, bit this is how it works.I get that part, as it's the same in PHP (I'm really a PHP developer.) In PHP this is true:"a"true1And this is false:"0"0false""What I still seems strange to me is that IniRead CONVERTS False to "False". In PHP, it would convert false to "". Keith Davis MCSA, ZCE, A+, N+ http://www.laurinkeithdavis.com Link to comment Share on other sites More sharing options...
ProgAndy Posted May 26, 2011 Share Posted May 26, 2011 What I still seems strange to me is that IniRead CONVERTS False to "False". In PHP, it would convert false to "".That is not strange at all. An ini-file contains only text (strings). So anything you read from an ini-file is a string. IniWrite converts all variables to a string before writing. Since AutoIt converts the boolean >False< to the string "False", and boolean >True< to "True", this is written to the file.PS: I don't think you have understood my last post completely. In AutoIt, even the string "0" equals true since its length is 1. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
laurin1 Posted May 26, 2011 Author Share Posted May 26, 2011 That is not strange at all. An ini-file contains only text (strings). So anything you read from an ini-file is a string. IniWrite converts all variables to a string before writing. Since AutoIt converts the boolean >False< to the string "False", and boolean >True< to "True", this is written to the file.PS: I don't think you have understood my last post completely. In AutoIt, even the string "0" equals true since its length is 1.Yes, that is strange.I'm not talking about a value READ from the INI file, I'm talking about the default value:$bSharedINIFile = IniRead($MASTERINIFILE, $SCRIPTNAME, 'SharedINIFile', False)The False here is NOT a string, but AutoIt is converting it into a string. Keith Davis MCSA, ZCE, A+, N+ http://www.laurinkeithdavis.com Link to comment Share on other sites More sharing options...
ProgAndy Posted May 26, 2011 Share Posted May 26, 2011 The default value has to be the same whether it is read from the ini or returned from the parameter if the value is missing. Inis return only strings, so the default value must always be a string. I think this behaviour is just natural. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
laurin1 Posted May 26, 2011 Author Share Posted May 26, 2011 The default value has to be the same whether it is read from the ini or returned from the parameter if the value is missing. Inis return only strings, so the default value must always be a string. I think this behaviour is just natural.Natural to return a string, sure, but to convert False to "False", that is not natural to me. Keith Davis MCSA, ZCE, A+, N+ http://www.laurinkeithdavis.com Link to comment Share on other sites More sharing options...
water Posted May 26, 2011 Share Posted May 26, 2011 Taken from the help file:Return Value Success: Returns the requested key value. Failure: Returns the default string if requested key not found.Therefore False is converted to the string "False". My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
pieeater Posted May 26, 2011 Share Posted May 26, 2011 $bSharedINIFile = IniRead($MASTERINIFILE, $SCRIPTNAME, 'SharedINIFile', False) If $bSharedINIFile = "false" then $bSharedINIFile = False Here's my fix. just add it after the ini read. [spoiler]My UDFs: Login UDF[/spoiler] 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