Using true and false

Discussion in 'Code Samples & Tips' started by klaus, Jan 30, 2008.

  1. klaus

    klaus Expert Licensed User

    I submit my experience (problem I had) with true and false.
    In my programs I use an Init file where I save setup settings and in particular CheckBox settings. This file is automatically saved at App_Close.
    To do that I used variables to store the CheckBox.Checked setting.
    These variables were saved in the Init file.
    The problem I had was on the device.

    The first time I used the program on the device, without having changed the values in the CheckBoxes these variables had the value of 0.

    After reading the file and setting
    CheckBox1.Checked=0 works in the IDE does not work on the device

    After checking and unchecking the CheckBox the variables become
    false which is OK.
    Before finding this I tried to use boolean variables declared as
    Dim CheckBox1_2(1) as boolean

    After reading the file
    CheckBox1.Checked=CheckBox1_2(0) works on the device but not in the IDE
    Erel, is this the same as in post?
    http://www.basic4ppc.com/forum/showthread.php?t=1604&highlight=true+false

    I solved the problem in not using variables any more and saving directly the Checked parameter
    FileWrite(c1,CheckBox1.Checked)
    and the same in reading
    CheckBox1.Checked=FileRead(c1)

    I added a small program that shows the different behaviours.

    Hope this could avoid some trouble to others.

    Klaus
    Switzerland
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    You should not declare arrays as booleans.
    Just use regular arrays or variables and it should work properly.

    Although on certain occasions you can use 0 and 1 as boolean values, it is not supported and you should use true / false constants instead.

    The bug described in this link was fixed in V6.05.
     
  3. klaus

    klaus Expert Licensed User

    Thank you Erel for your explanations.

    Klaus
     
Loading...