Jump to content

iniRead bug? Where am I wrong?


Rhodney
 Share

Recommended Posts

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)
EndIf

My mycfg.ini file in temp folder:

[Parametros]
StoreBool=False

This proves that the function iniRead found my ini file in the Temp folder and assigned the value False for it.

Posted Image

If it is False, because it's falling on the block "True" of the "If"

Posted Image

Sorry for bad english...

I making a big mistake here or really is a bug of iniRead function?

Thank you in advance.

Link to comment
Share on other sites

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 by wraithdu
Link to comment
Share on other sites

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. :mellow:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! :mellow:
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...