08-06-2025, 06:44 PM
Is there any way that a Type declaration can be variable?
For example, the following code works, but the length is static.
Type ContactRecord
Name As String * 30 ' Fixed-length string for name
Phone As String * 15 ' Fixed-length string for phone number
End Type
If I were to enter something like (and yes, I realize this is invalid code...):
name.fieldlen% = 30
phone.fieldlen% = 15
Type ContactRecord
Name As String * name.fieldlen% ' Fixed-length string for name
Phone As String * phone.fieldlen% ' Fixed-length string for phone number
End Type
I get an error "Invalid number/constrant after STRING * type"
What I am trying to achieve is the ability to create a random access file, but be able to set the field length dynamically. This would allow me to create basic databases on the fly without having to specify the records statically. The database can then be created from information gleaned from outside sources and the database's record sizes are determined from within the running code.
One thought was to set the record length to the max that I would expect to use so that is is a 'max-size fits all', but there will be a lot of records and this will make the file sizes unnecessarily large.
For example, the following code works, but the length is static.
Type ContactRecord
Name As String * 30 ' Fixed-length string for name
Phone As String * 15 ' Fixed-length string for phone number
End Type
If I were to enter something like (and yes, I realize this is invalid code...):
name.fieldlen% = 30
phone.fieldlen% = 15
Type ContactRecord
Name As String * name.fieldlen% ' Fixed-length string for name
Phone As String * phone.fieldlen% ' Fixed-length string for phone number
End Type
I get an error "Invalid number/constrant after STRING * type"
What I am trying to achieve is the ability to create a random access file, but be able to set the field length dynamically. This would allow me to create basic databases on the fly without having to specify the records statically. The database can then be created from information gleaned from outside sources and the database's record sizes are determined from within the running code.
One thought was to set the record length to the max that I would expect to use so that is is a 'max-size fits all', but there will be a lot of records and this will make the file sizes unnecessarily large.


