Sub AddPerson(p As PersonType)
'Calc index of the new element:
PersonArrayCount = PersonArrayCount + 1
'Is there still free space?
If PersonArrayCount > PersonArray.Length Then 'No!
'In classic VB I would simply use this line:
' ReDim Preserve PersonArray(2 * PersonArrayCount)
'But "Preserve" does not exists in b4a, so do it manualy...
'Save the old data:
Dim PersonCache(PersonArray.Length) As PersonType
Dim i As Int
For i = 0 To PersonArray.Length - 1
PersonCache(i) = PersonArray(i)
Next'i
'Redim the array and copy the old data back:
Dim PersonArray(2 * PersonArrayCount) As PersonType
For i = 0 To PersonCache.Length - 1
PersonArray(i) = PersonCache(i)
Next'i
End If
'Finaly save the new element:
PersonArray(PersonArrayCount - 1) = p
End Sub