Rhodney Posted February 26, 2010 Posted February 26, 2010 Could anyone help me? I'm having problems with boolean variables types, loaded by iniRead().I can read the ini file, the variable takes the value of ini file, but in the logical operations, they variables seem to be with the default value used in the iniRead() call.My code:Global $MyBool = IniRead(@TempDir & "\mycfg.ini", "Parametros", "StoreBool", True) MsgBox(0, "Before", "$MyBool is " & $MyBool) If $MyBool Then MsgBox(0, "Execute this only if $MyBool is TRUE", "$MyBool is " & $MyBool) Else MsgBox(0, "Execute this only if $MyBool is FALSE", "$MyBool is " & $MyBool) EndIfMy mycfg.ini file in temp folder:[Parametros] StoreBool=FalseThis proves that the function iniRead found my ini file in the Temp folder and assigned the value False for it.If it is False, because it's falling on the block "True" of the "If"Sorry for bad english...I making a big mistake here or really is a bug of iniRead function?Thank you in advance.
wraithdu Posted February 26, 2010 Posted February 26, 2010 (edited) You realise the result of every IniRead is a string right? Any string that is not "" (empty) is logically true. So, you need to rework your logic tests. Either store your ini bools as 0's and 1's or test $MyBool = "true" / "false". Edited February 26, 2010 by wraithdu
Rhodney Posted February 26, 2010 Author Posted February 26, 2010 On 2/26/2010 at 2:19 AM, 'wraithdu said: You realise the result of every IniRead is a string right? Any string that is not "" (empty) is logically true. So, you need to rework your logic tests. Either store your ini bools as 0's and 1's or test $MyBool = "true" / "false".Thanks wraithdu! If I change to 0's and 1's it works, but then there is how to store booleans in ini files?"If $BoolVar Then" is better than "If $IntVar = 1 Then". Because in the second case the code becomes dirty, especially if I use many variables, "Ands", "Ors" and "Nots"... Because I need this very much.
UberNuss Posted February 26, 2010 Posted February 26, 2010 Rodney, try this when you write and read a boolean value to a .ini file: Global $MyBool $MyBool = True ; write ... IniWrite(@TempDir & "\mycfg.ini", "Parametros", "StoreBool", String(Number($MyBool))) ; read ... $MyBool = IniRead(@TempDir & "\mycfg.ini", "Parametros", "StoreBool", True) $MyBool = Number($MyBool); MyBool is now a working boolean. Das Häschen benutzt Radar.
Rhodney Posted February 26, 2010 Author Posted February 26, 2010 On 2/26/2010 at 2:59 AM, 'UberNuss said: Rodney, try this when you write and read a boolean value to a .ini file: Global $MyBool $MyBool = True ; write ... IniWrite(@TempDir & "\mycfg.ini", "Parametros", "StoreBool", String(Number($MyBool))) ; read ... $MyBool = IniRead(@TempDir & "\mycfg.ini", "Parametros", "StoreBool", True) $MyBool = Number($MyBool); MyBool is now a working boolean. Very thanks UberNuss! It works perfect!
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