B4J Question [SOLVED] B4XPages / Exchanging values between different pages not working all the time

christianjeannot

Member
Licensed User
Hello community,

in my app I use different pages. I use the following code on page 2 to update values in the main page.

Page 2:
B4X:
Private Sub B4XPage_Disappear
    SaveString = "Active Profile" & ";" & cbProfile.SelectedItem
    File.WriteString(DataProfileFolder, "Dicy_Active_Profile.txt", SaveString)
    Log("Sub: B4XPage_Disappear; Active Profile written")
    ActiveProfileIndex = cbProfile.SelectedIndex
    Log($"Sub: B4XPage_Disappear; Active Profile Index: ${ActiveProfileIndex}"$)
    B4XPages.MainPage.Update
End Sub

Main Page:
B4X:
Public Sub Update
    cBoxProfile.SelectedIndex = ManageProfilePage.ActiveProfileIndex
    Log($"Manage profile; Active Profile Index: ${ManageProfilePage.ActiveProfileIndex}"$)
    Log($"Main Page; Active Profile Index: ${cBoxProfile.SelectedIndex}"$)
End Sub

When I test my app I have sometimes situations where I can see in the log that the values on page 2 are correct recognized on the main page but the SelectedIndex still stays in the old value. I do not know why.

Log:
Rich (BB code):
Sub: B4XPage_Disappear; Active Profile Index: 13
Manage profile; Active Profile Index: 13
Main Page; Active Profile Index: 6

Which mistake I made?

Is there a way that I can better debug this situation?

Best regards

--Christian
 

roerGarcia

Active Member
Licensed User
Longtime User
From Spanish, translated by google.
I do not remember if the selected index of the combo can be assigned that way and I cannot test the code in B4A at the moment. Have you checked that?

cBoxProfile.SelectedIndex = ManageProfilePage.ActiveProfileIndex
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Maybe the SelectedIndex is updated in another place?

Generally speaking, the usage of B4XPage_Appear / Disappear can be a sign that you are making things more complicated then they should be, and treating the pages as activities.
You can directly update the state of other (created) pages at any point you like.
 
Upvote 0

christianjeannot

Member
Licensed User
@roerGarcia
I will test it

@Erel
I am specialist in making things complicated šŸ˜‡

I have checked my code and find no place where I touch SelectedIndex and found nothing but I use global variables. Maybe I have an error somewhere there.
I will check if I can find a better way to update this value.

I guess I should spend more time reading more documentation about the design from B4X but as you said in one of your Videos you have to code to get experience.
 
Upvote 0

christianjeannot

Member
Licensed User
Hello community,

I found the error :). As most of the time the error is in front of the keyboard (grrrr).

I am adding an item to a combo box in page 2. I try to use this new index (new item combo box page 2) on the combo box in page one. This will not work as this new index does not exist at this moment at the combo box in page 1. So I have to load the combo box new or add the item. Then I can use this index.

It seems that B4Xpages / B4XComboBox uses the last used index in my situation when I refer to an index value which does not exist. Is it normal that there is no error message that I try to refer to an index that does not exist?

Best regards

--Christian
 
Upvote 0
Top