iOS Question String with two dimension different behavior between b4i and b4j

mike2ppc

Member
Licensed User
Hello,

I have defined a string variable with 2 dimensions. If I execute this code in B4i I get a different result like in b4j.
I would expect the same result in b4i as in B4j. Can someone explain me what I am doing wrong?

dim lv_array(2,2) as string
lv_array(0,0) = "containername"
lv_array(0,1) = "text"
lv_array(1,0) = "fieldname"
lv_array(1,1) = "text"

Result in B4J:
lv_array
-0
---0 containername
---1 text
-1
---0 fieldname
---1 text

Result in B4i
lv_array
0 containername
1 text
2 fieldname
3 text

Many thanks in advance
Michael
 

mike2ppc

Member
Licensed User
Problem solved, it works this way.

B4i example:
B4X:
Sub Process_Globals
    Public App As Application
End Sub

Private Sub Application_Start (Nav As NavigationController)
    buildarray
End Sub

Sub buildarray
    Dim lv_array(2,2) As String
    lv_array(0,0) = "containername"
    lv_array(0,1) = "text"
    lv_array(1,0) = "fieldname"
    lv_array(1,1) = "text"
    workwitharray(lv_array,2)
End Sub

Sub workwitharray(in_array(,) As String, in_count As Int)
For i = 0 To in_count-1
    Log(i & "," & 0 & " = " & in_array(i,0))
    Log(i & "," & 0 & " = " & in_array(i,1))
Next
End Sub
B4J example:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    buildarray
End Sub

Sub buildarray
    Dim lv_array(2,2) As String
    lv_array(0,0) = "containername"
    lv_array(0,1) = "text"
    lv_array(1,0) = "fieldname"
    lv_array(1,1) = "text"
    workwitharray(lv_array,2)
End Sub

Sub workwitharray(in_array(,) As String, in_count As Int)
    For i = 0 To in_count-1
        Log(i & "," & 0 & " = " & in_array(i,0))
        Log(i & "," & 0 & " = " & in_array(i,1))
    Next
End Sub
 
Top