VAKU123 Posted October 2, 2018 Share Posted October 2, 2018 Hi, I have a script with external .INI config file. I wanted to make simple validation of setting in config file. This is a basic thing every autoit scripter would want to do every day. If Config.ini has: [Settings] AUTORUN=1 or: [Settings] AUTORUN=0 Then comparison operator '<>' correctly treats $AUTORUN variable and AURORUN setting from config file - as different and executes correctly. BUT when I specify non-numeric value for AUTORUN in Config.ini, for example: AUTORUN=A0, then for NO REASON AutoIt's '<>' comparison operator treats "A0" as equal to '0', which is a strange and unexpected behavior. WTF is this? How can it be made so an ELEMENTARY Thing - doesn't work as it makes sense for any reasonable man ? Here is a simple sample of code: Global $AUTORUN = 0 $config = "Config.ini" Local $aSettings = IniReadSection($config, "Settings") If Not @error Then For $i = 1 To $aSettings[0][0] $SettingKey = $aSettings[$i][0] $SettingValue = $aSettings[$i][1] Switch $SettingKey Case "AUTORUN" If($AUTORUN <> $SettingValue) Then ; ! If I specify in config file: AUTORUN=A0, then it never gets here ! ; For no reason it treats "A0" as equal to 0, which is - A COMPLETELY UNEXPECTED BEHAVIOR OF AUTOIT ! ; How can one rely on such elementary functionality as COMPARISON OPERATORS '==', '<>' if this is NOT BEHAVING AS IT SUPPOSED TO ?! ConsoleWrite("Setting Change: Option 'AUTORUN', previous value: '" & $AUTORUN & "', new value: '" & $SettingValue & "'.") $AUTORUN = $SettingValue EndIf Case Else ConsoleWrite("Error: Invalid option '" & $SettingKey & "' in config file '" & $config & "'.") Exit 1 EndSwitch Next EndIf Link to comment Share on other sites More sharing options...
Developers Jos Posted October 2, 2018 Developers Share Posted October 2, 2018 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team 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 October 2, 2018 Developers Share Posted October 2, 2018 3 minutes ago, VAKU123 said: BUT when I specify non-numeric value for AUTORUN in Config.ini, for example: AUTORUN=A0, then for NO REASON AutoIt's '<>' comparison operator treats "A0" as equal to '0', which is a strange and unexpected behavior. WTF is this? How can it be made so an ELEMENTARY Thing - doesn't work as it makes sense for any reasonable man ? Maybe it means you are assuming things? If you would have taken the time to read some of the basics in the helpfile you would understand why this is happening. In this case you can find the details in the Helpfile/Language Reference - Operators: Quote Comparing different datatypes Care is needed if comparing mixed datatypes, as unless the case-sensitive (==) string operator is used, mixed comparisons are usually made numerically. Most strings will be evaluated as 0 and so the result may well not be the one expected. It is recommended to force the items being compared into the same datatype using Number()/String() before the comparison. So...No Bug. Jos user4157124 1 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...
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