Android Question Custom Types-reusing a variable previously declared as a Custom Type

Andy Whitehouse

Member
Licensed User
Longtime User
Hi,

I am working with two custom types.

They are exactly the same as each other in data structure except the second type has more arrays in it than the first i.e.

First type:

Type FullTransitRecord (NoofDaysDataStored AsByte, SubjectCoreDetails AsSubjectCoreDetail, SubjectDatesandAllPlanetDataRecords (32) AsSubjectDateandAllPlanetDataRecords, SubjectHouseDetails (32) AsSubjectHouseDetail, SubjectSignDetails (32) AsSubjectSignDetail)

Second Type:

Type FullNatalRecord (NoofDaysDataStored AsByte, SubjectCoreDetails AsSubjectCoreDetail, SubjectDatesandAllPlanetDataRecords (2) AsSubjectDateandAllPlanetDataRecords, SubjectHouseDetails (2) AsSubjectHouseDetail, SubjectSignDetails (2) AsSubjectSignDetail)

The only difference between the two is that the second type only has two arrays whereas the first type has 32 arrays.

What I am trying to do is assign a type to one variable dependent on the result of a conditional test - e.g.

if x = 1 .... dim Currentuser as FullTransitRecord
if x = 2 .... dim Currentuser as FullNatalRecord


However, once "Currentuser" has been assigned to a type, it seems impossible to erase, Re - Dim it or reassign its type - even as a module variable*, and I get the error "Current Declaration does not match previous one".

* I understand that Types, and variables connected with them, are Public by their nature)

If I were able to redeclare the variable "currentuser" then this would avoid a lot of data swapping and allow the same code module to access both types - the method would be the same as the data structures are the same for all intents and purposes.

Anyone know if this is possible?

If it isn't possible then I can use FullTransitRecord as the type for everything but this means I have allocating data / memory space when the full 32 arrays are not needed, and I will declare the FullNatalRecord far more out of the two types.

Thanks in advance.

Andy
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is not possible. The compiler needs to know the type of object.

However unless you create more than 100,000 objects of these types then I don't think that you will be able to measure any difference between the two types.

With that said, you can use a List instead of an array. The list will grow as needed.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…