Help with structrure, array..

padvou

Active Member
Licensed User
Longtime User
Here's the code snippet from VB:
B4X:
Structure ItemR                'Declare a custom structure
        Dim Rr As Double
        Dim RX As Double
        Dim RY As Double
        Dim idx As String
    End Structure

sub
Dim myarray(128) As ItemR        'dim an array as our custom structure
For m as integer =0 to 127
myarray(m).Rr = somenumber
myarray(m).RX = somenumber
myarray(m).RY = somenumber
myarray(m).idx = "sometext"
next

 Dim maxvalue1 As Integer = 0       'Find the max value
        For Each item As ItemR In myarray
            If item.Rr > maxvalue1 Then maxvalue1 = item.Rr
       Next
end sub

Could someone please help with migrating this code to basic4android?
 

enonod

Well-Known Member
Licensed User
Longtime User
I think this will do it

Type ItemR(Rr As Double, RX As Double, RY As Double, idx As String)
Dim m,i as int ' or use m twice

Sub Fred 'needs a name
Dim myarray(128) As ItemR 'dim an array as our custom structure
For m =0 to 127
myarray(m).Rr = somenumber
myarray(m).RX = somenumber
myarray(m).RY = somenumber
myarray(m).idx = "sometext"
next

Dim maxvalue1= 0 As Int
'Find the max value
For i=0 to127
If myarray(i).Rr > maxvalue1 Then maxvalue1 = myarray(i).Rr
Next

End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Not much to change. Try This:

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

Type ItemR (Rr As Double, RX As Double,RY As Double,idx As String)

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.

End Sub
Sub Activity_Create(FirstTime As Boolean)

SomeNumber = 12  'Just to get it to work

Dim myarray(128) As ItemR        'dim an array as our custom structure
For m  = 0 To 127
   myarray(m).Rr = somenumber
   myarray(m).RX = somenumber
   myarray(m).RY = somenumber
   myarray(m).idx = "sometext"
Next

Dim maxvalue1 As Int = 0       'Find the max value
For Each item As ItemR In myarray
    If item.Rr > maxvalue1 Then maxvalue1 = item.Rr
Next
Log(maxvalue1)
   
End Sub
 
Upvote 0
Top