Android Question Structures

Terradrones

Active Member
Hi All

Need help again please.

I am adding the Coordinates of all the corners of a Terrace to a temporary Array, before I save them to a SQLite database. In vb.net, I could have a structure as follows:

B4X:
[/
   Dim TModel(200) As TerraceModel

    Structure TerraceModel
        Dim Pnt As String
        Dim Y As Double
        Dim X As Double
        Dim Z As Double
    End Structure
]

And I would save them in the array as follows:

[CODE=b4x][/
        For i1 = 0 To VertexNo
            SaveTerrace(TModel(i1).Pnt, TModel(i1).Y, TModel(i1).X, TModel(i1).Z)
        Next

How can I do this in B4A?

Thanks
Michael

]
 

Mahares

Expert
Licensed User
Longtime User
I am adding the Coordinates of all the corners of a Terrace to a temporary Array
I would use a custom Type, store the data in a list, use serializator to convert the list to bytes, and save to a file read the file bytes and convert to a list when you need them before storing to your database.
B4X:
Type TerraceModel( Pnt As String,  X As Double, Y As Double, Z As Double)  'in Class_Globals
B4X:
    Dim MyList As List
    MyList.Initialize
    Dim VertexNo As Int = 200
    For i= 0 To VertexNo -1
        MyList.Add(CreateTerraceModel ("Point" & i, i, i+5.5, i*2+ 13.65))  'use your own dappropriate data
    Next
  
    'Save custom type list to a file
    Dim ser As B4XSerializator
    Dim bytes() As Byte = ser.ConvertObjectToBytes(MyList)
    File.WriteBytes(xui.DefaultFolder,"mytype.dat",bytes)
  
    'Below read custom type file list
    Dim bytes() As Byte = File.ReadBytes(xui.DefaultFolder,"mytype.dat")
    Dim l As List = ser.ConvertBytesToObject(bytes)

    'display data to confirm their presence or save the data to your database:

B4X:
Public Sub CreateTerraceModel (Pnt As String, X As Double, Y As Double, Z As Double) As TerraceModel
    Dim t1 As TerraceModel
    t1.Initialize
    t1.Pnt = Pnt
    t1.X = X
    t1.Y = Y
    t1.Z = Z
    Return t1
End Sub
As a side note, you are still not putting your code inside code tags properly. See your code. You will see a lot of stray stuff
Also, a word of advice: when you are happy with an answer, it is sometimes better to give a 'like' rather put an unnecessary post that just says 'Thank you' unless you have a follow up. The fewer posts a thread has the more people are willing to read it.
Added this line a few hours later: If you continue to have problems, do not hesitate to put your code or project and ask.
 
Last edited:
Upvote 1
Top