How to declare double type dynamic array

gkumar

Active Member
Licensed User
Longtime User
How to declare a double type dynamic array, whose array size is determined in runtime? It should be like Map.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'd use a list.

Then you just push your custom type into the list.
They're very flexible.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
If I am understanding what you are asking you could do something like:

B4X:
Sub Process_Globals
End Sub
Sub Globals
   Dim MyVar(10, 10) As String  'Setup the Double array here
   For l = 0 To MyVar.Length -1
      MyVar(l,0) = "ABC" : MyVar(l,1) = l & ""
   Next   
End Sub
Sub Activity_Create(FirstTime As Boolean)
End Sub
Sub Activity_Resume
   AddToDoubleArray("bbb", "10")
   Dim s As String : s = ""
   For l = 0 To MyVar.Length -1
      s = s & MyVar(l,0) & ", " & MyVar(l,1) & CRLF
   Next
   Msgbox(s, MyVar.Length)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub AddToDoubleArray(Val1 As String, Val2 As String)  'Call this sub to add to it and adjust size
   Dim hv(MyVar.Length + 1, MyVar.Length + 1) As String
   For l = 0 To MyVar.Length -1
      hv(l, 0) = MyVar(l, 0) : hv(l, 1) = MyVar(l, 1)
   Next
   hv(MyVar.Length, 0) = Val1 : hv(MyVar.Length, 1) = Val2
   Dim MyVar(MyVar.Length + 1, MyVar.Length + 1) As String
   For l = 0 To MyVar.Length -1
      MyVar(l, 0) = hv(l, 0) : MyVar(l, 1) = hv(l, 1)
   Next
End Sub
 
Upvote 0

awakenblueheart

Member
Licensed User
Longtime User
Erel or anyone..help me

'Activity module
Sub Process_Globals

End Sub

Sub Globals
Dim equationmaxpower As EditText
Dim maxpowr As Double
Dim coefficient As Double
'Dim resultss As Double
Dim i As Double
Dim cofx() As Double
Dim coDfx() As Double
Dim a As Double
Dim maxpowrDfx As Double
'Dim eps As Double 'epsilon

End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("findrootLayout")
End Sub

Sub findrootButton_Click


If equationmaxpower.Text = "" Then
Msgbox("Insert a value","")
Return
Else

If equationmaxpower.Text = 0 Then
Msgbox("Insert a value more than 0","")
Return

Else
If Not(equationmaxpower.Text = "") Then
maxpowr = equationmaxpower.Text
coefficient = maxpowr + 1

Dim cofx(maxpowr) As Double
Dim coDfx(maxpowr - 1) As Double


coDfx(0) = 0

For i = 0 To maxpowr
StartActivity(Submain)
a = Submain.coefficient2
cofx(i) = a
Next



maxpowrDfx = maxpowr - 1

For i = 0 To maxpowrDfx
coDfx(i) = cofx(i) * (maxpowr - i)
Next


' eps = 1
' While eps + 1 > 1
'eps = eps / 2
'End While



'resultss = results(eps, cofx, coDfx, maxpowr, maxpowrDfx)
'root.Text = resultss
End If
End If
End If
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Above is the first layout...
Below is the second layout.

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim coefficient2 As Double
coefficient2=""
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim coefficient As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("2")
End Sub

Sub next_Click

If coefficient.Text = "" Then
Msgbox("Insert a value","")
End If
If Not (coefficient.Text = "") Then
coefficient2= coefficient.Text
StartActivity(Main)
End If
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

I am a very beginner of B4A..
The emulator can not run this.
May I know the problem?
 
Upvote 0
Top