Reading lists with types records

CharlesR

Member
Licensed User
Longtime User
This is a real newbie question, but I cannot read the records in a list with types in it. The code below shows what I am trying to do but for some reason(probably very silly) I only get the last record.

Thanks for your help.

Charles :sign0085:

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

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 List1 As List
Type Test(num As Int, let As String)
Dim Demo As Test
End Sub

Sub Activity_Create(FirstTime As Boolean)
List1.Initialize
Loaddata
Fetchdata
End Sub

Sub Loaddata
Demo.num = 1
Demo.let = "A"
List1.Add(Demo)
Demo.num = 2
Demo.let = "B"
List1.Add(Demo)
Demo.num = 3
Demo.let = "C"
List1.Add(Demo)
Demo.num = 4
Demo.let = "D"
List1.Add(Demo)
End Sub

Sub Fetchdata
Dim Tempdata As Test
Tempdata.Initialize
Dim i, tnum As Int
Dim tlet As String
For i = 0 To List1.Size - 1
Tempdata = List1.Get(i)
tnum = Tempdata.num
tlet = Tempdata.let
Msgbox(i &" " & tnum & tlet," ")
Next
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

CharlesR

Member
Licensed User
Longtime User
Thank you for that. I have worked through the example and I think I can see that, but I am still unable to see how to modify my code so I can access my list?

Charles
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Sub LoadData should be:
B4X:
Sub Loaddata
Dim Demo As Test
   Demo.num = 1
   Demo.let = "A"
   List1.Add(Demo)
Dim Demo As Test
   Demo.num = 2
   Demo.let = "B"
   List1.Add(Demo)
Dim Demo As Test
   Demo.num = 3
   Demo.let = "C"
   List1.Add(Demo)
Dim Demo As Test
   Demo.num = 4
   Demo.let = "D"
   List1.Add(Demo)
End Sub
By calling Dim you create a new object.
 
Upvote 0

CharlesR

Member
Licensed User
Longtime User
Thank you Erel. In my main program, I had been trying to find the calculation error when in fact I was storing the original list incorrectly.


Charles
 
Upvote 0
Top