Android Question Array of custom types - can I do this?

Arf

Well-Known Member
Licensed User
Longtime User
I've made a type, like this:
B4X:
Type ThisPatExamsForUpload (ULpat As PatientStruct, ULexam() As Exam)

Which contains patient data, and a bunch of exams for that patient - there could be any number of exams.
When I try populate the instance, I get a exception when I try initialise the first ULexam() - ArrayIndexOutOfBounds.

B4X:
PatAndExams.ULexam(j).Initialize
PatAndExams.ULexam(j) = exm

I understand the error occurs as PatAndExams.ULexam(0) does not exist yet. How can I create ULexam(0) and subsequent exams in that array in order that they can be initialised?

Thanks
 

Arf

Well-Known Member
Licensed User
Longtime User
Thanks.
Well this chunk of patients and exam data needs to be sent to a PC and then unpacked into a database on the PC, and with my programming skills not being very strong, I thought I'd start simple - and arrays seem the simpler data type, and I probably stand the best chance of ending up with a well defined structure to transport.

I may be completely wrong on my approach and have to do something completely different.. living and learning :)
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Thanks.
Well this chunk of patients and exam data needs to be sent to a PC and then unpacked into a database on the PC, and with my programming skills not being very strong, I thought I'd start simple - and arrays seem the simpler data type, and I probably stand the best chance of ending up with a well defined structure to transport.

I may be completely wrong on my approach and have to do something completely different.. living and learning :)
If your type has only two fields and one is an unique ID, you may also use a map. Instead of:
Type ThisPatExamsForUpload (ULpat As PatientStruct, ULexam As List)
Dim TPEfU(10) as ThisPatExamsForUpload
...
you could have:
Dim PatExamsForUpload as Map
PatExamsForUpload.Put(ULpat, ULExam)
 
Upvote 0
Top