08-06-2025, 06:49 PM
(08-06-2025, 06:44 PM)dano Wrote: 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.
I don't think you'll ever see variable length TYPE's. One way you could accomplish the same end (with slightly More coding) Is to have a Data Length Field in you type and have that data in a **REDIMMED** array that you PUT to the file immedietly after the TYPE variable. You can REDIM an Array as many times as you want to and an entire Array can be written to (and read from) with a Single PUT, GET instruction !

