Android Question Boolean will not respond to code in Activity_Create

Carthalion

Member
Licensed User
Longtime User
This should be simple, but it is a mystery. I want a login panel to be visible in the Main Activity.

I get no error. I check with a message box. The FolderName is "Demo". This should make LogYn = True. But it is always false. It does not make sense.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("MainMenu")
    Dim FolderName As String
    FolderName = File.ReadString(File.DirRootExternal, "QQFiles/FolderName.txt")
    Dim LogYn As Boolean
    If FolderName = "Demo" Then LogYn= True 'FolderName is "Demo"; LogYn is False
    If LogYn =True Then pnlLogin.Visible= True
End Sub
 

JordiCP

Expert
Licensed User
Longtime User
Make sure that your file does not contain any space or newline (CR and/or LF) character after the "Demo" string
Also make sure that your file is ANSI-encoded. The size of this file should be 4 bytes
 
Upvote 0

Carthalion

Member
Licensed User
Longtime User
Make sure that your file does not contain any space or newline (CR and/or LF) character after the "Demo" string
Also make sure that your file is ANSI-encoded. The size of this file should be 4 bytes

I checked. No space, CR etc. The file starts as ANSI-encoded and is uploaded using File.copy. Then it is downloaded using File.ReadString(File.DirRootExternal. The file gets read OK, and it is "Demo" as expected. All this happens for the purpose of storing the file related to the individual user. However, the
IfFolderName = "Demo" does not give a positive response.

Maybe when the file is copied to DirRootExternal and then copied back it loses its ANSI-encoding.

Other than this, I have no idea why it would not work. I appreciate your input.
 
Upvote 0

Carthalion

Member
Licensed User
Longtime User
This is a mistake. You should use Log instead.

What is the output of:
B4X:
Log(FolderName)
Log(FolderName.Length)

In the Log window after:

B4X:
Log(FolderName.Length)
    If FolderName = "Demo" Then LogYn= True
    If LogYn =True Then pnlLogin.Visible= True

LogCat connected to: B4A-Bridge: samsung SCH-I545
--------- beginning of main
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:QuickQualifier.com
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
"Demo"
6
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **

This does not work:

If FolderName = "Demo"Then LogYn= True'FolderName is "Demo"; LogYn is FalseIf LogYn =TrueThen pnlLogin.Visible= True
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Your String contains the " too!
Try this check
B4X:
If FolderName = $""Demo""$ Then LogYn= True
 
Upvote 0

Carthalion

Member
Licensed User
Longtime User
Yep. Was typing, too :)

B4X:
Dim a As String
    a= """Demo"""
    Log (a)
  
    If a="""Demo""" Then Log("True")
That was it. Quotes around the quotes. I also found that using the Contains property works:

If (FolderName.Contains("Demo")) Then LogYn= True

Thanks!
 
Upvote 0
Top