Bug? B4i - Switch problem: Value or Checked --> write to file "True" and reading "0x1"

Picon

Member
Licensed User
Hi everyone

In B4i I am using the Switch As B4XView object and I have a problem with its basic property:
- "Value" is in the Visual Designer ("Checked" is missing)
- in the IDE (code) "Checked" is available ("Value" is missing)

When writing to a file
B4X:
DataList_1.Clear
DataList_1.Add(Switch1.Checked)
File.WriteList (File.DirDocuments, <file_name>, DataList_1)
Checked value is stored in DataList_1 as "True"

After reading the file

B4X:
DataList_1 = File.ReadList (File.DirDocuments, <file_name>)
with the ListATSet.Get (0) command I find the value 0x1 (HEX) - not "True"

Code:
B4X:
Switch1.Checked = ListATSet.Get (0)
does not work properly: the "Switch1.Checked" will still be "False" despite typing 0x1

No error is reported for this record.

The error will appear only when I write directly in the code:
B4X:
Switch1.Checked = 1       '  (or 0x1).

Could the slight difference in the availability of "Value" and "Checked" (in Switch1) have something to do with the fact that I write to the file "true" and read "0x1"?

assignment to a Boolean variable also fails:
B4X:
Variable1 = DataList_1.Get(0)
'  false          1(0x1)         <----result
 
Last edited:

emexes

Expert
Licensed User

1/ what puts values into the list ListATSet ?

2/ is it possible to show us (attach to post) the file that is read by File.ReadList ?
 

Picon

Member
Licensed User
1/ what puts values into the list ListATSet ?

2/ is it possible to show us (attach to post) the file that is read by File.ReadList ?
#1: ' put values into the clean list:
B4X:
DataList_1.Clear
DataList_1.Add(Switch.Checked)   ' alternatively as a parameter I tried to use a variable in which I had "Switch.Checked"
DataList_1.Add(EditText1.Text)
DataList_1.Add(EtitText2.Text)

File.WriteList(File.DirDocuments, <nazwa_pliku>, DataList_1

#2:
I don't know (can't find it) the physical location of the file on the iPhone. The save routine doesn't explicitly tell you where the file is.
 

emexes

Expert
Licensed User
2/ is it possible to show us (attach to post) the file that is read by File.ReadList ?
#2:
I don't know (can't find it) the physical location of the file on the iPhone. The save routine doesn't explicitly tell you where the file is.

No worries, try Plan B, which should convert all list elements to strings, same as File.WriteList() should be doing:

B4X:
Log(DataList_1)
 

emexes

Expert
Licensed User
WriteList() should be converting all types to strings, and thus ReadList() will be returning an array of all strings, since it doesn't know whether a line with the three characters "0", "x" and "1" on it is supposed to be a string or an int or a boolean.

But whatever string values the boolean true or false values are converted to, that conversion should work in the opposite direction too.

Try this, to make sure that booleans are converting ("casting") to strings and back again ok, and what the strings are:

B4X:
Dim TestBoolean1 As Boolean
Dim TestBoolean2 As Boolean
Dim TestString As String

Log("Try boolean false")
TestBoolean1 = False
TestString = TestBoolean1
TestBoolean2 = TestString
Log(TestBoolean1)
Log("[" & TestString & "]")
Log(TestBoolean2)

Log("Try boolean true")
TestBoolean1 = True
TestString = TestBoolean1
TestBoolean2 = TestString
Log(TestBoolean1)
Log("[" & TestString & "]")
Log(TestBoolean2)

Log("Try boolean false again, to be sure, to be sure")
TestBoolean1 = False
TestString = TestBoolean
TestBoolean2 = TestString
Log(TestBoolean1)
Log("[" & TestString & "]")
Log(TestBoolean2)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…