B4J Question [ABMaterial] [SOLVED] Realtime calculation between ABMInput

Magma

Expert
Licensed User
Longtime User
Hi there...

I was searching the b4x forum for ABMInput calculations (actually realtime) and haven't found anything...

I was hoping the following code working - but obviously making something wrong :-(

Where am I wrong... ?

B4X:
Sub Class_Globals
    Dim inp1 As ABMInput
    Dim inp2 As ABMInput
    Dim inp3 As ABMInput
....

Sub ConnectPage()
...
    inp1.Initialize(page, "inp1",ABM.INPUT_NUMBER, "A Number", False, "input")
    inp1.RaiseChangedEvent=True
    inp1.RaiseFocusEvent=True
    page.Cell(2,1).AddComponent(inp1)

    inp2.Initialize(page, "inp2",ABM.INPUT_NUMBER, "B Number", False, "input")
    inp2.RaiseChangedEvent=True
    inp2.RaiseFocusEvent=True
    page.Cell(3,1).AddComponent(inp2)

    inp3.Initialize(page, "inp3",ABM.INPUT_NUMBER, "C Number", False, "input")
    inp3.RaiseChangedEvent=True
    inp3.RaiseFocusEvent=True
    page.Cell(4,1).AddComponent(inp3)
....

Sub inp1_changed(value As String)
    If inp1.Text.Length>0 Then
        inp3.Text=inp1.Text+inp2.text
        'inp1.refresh
        'inp2.refresh
        'inp3.Refresh
    End If
End Sub

Sub inp2_changed(value As String)
    If inp2.Text.Length>0 Then
        inp3.Text=inp1.Text+inp2.text
        'inp1.refresh
        'inp2.refresh
        'inp3.Refresh
    End If
End Sub
 

alwaysbusy

Expert
Licensed User
Longtime User
You have to 'retake' the Component. It is only then that B4J will go to the browser and look for the current value.

So something like:
B4X:
' when you want to GET the current value:
inp1 = Page.Component("inp1") '<----------------- this will update the 'B4J' side with the value from the component at the browser side.
inp2 = Page.Component("inp2")
inp3 = Page.Component("inp3")

'now you can do
inp3.Text=inp1.Text+inp2.text
inp3.refresh ' <--- and refresh, so update the 'browser' side with the B4J side

But as you just pointed out in your latest remark, for this example it is possibly indeed better to use the 'value'.

So in short, if you want to GET the current value on the Browser side of an ABM Component, you must use the .Component() method of its parent. In your case it is now on Page level, but it can be that it is in (nested) ABMContainers or e.g. a ModalSheet too and then you have to use their .Component() method.

Alwaysbusy
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
You have to 'retake' the Component. It is only then that B4J will go to the browser and look for the current value.
Yes, I often get tripped up when and what component to refresh to see anew value....
Soon we learn.
 
Upvote 0
Top