If you require the user to inform the field size you still have a fixed-length string. Having to inform it for each record sounds extremely counterproductive.
I'm of the opinion that everything should be handled by QB64. Storing the record length immediately before the string is what sounds more viable.
Just out of curiosity, just how does it(QB64) maintain the size of variable length strings normally? I mean how does a variable length string normally get stored and recalled?
Instead of worrying about storing the length could we use a string terminator character like tacking chr$(255) to the end of the string, so when the programmer wants to pull that value out and use it QB knows where the string stops? would that work when using GET and PUT with a TYPE too, as it would know that the string ends with &Hff and the next byte belongs to the next variable?
Using a field_value to define lenght of string with accuracy (the solution of Fellippe to write at the end the size of string)
The only issue with that is if the user has a string which already contains that character. Then you'll end up terminating the string at that point.
And that's if you set a 2GB (or 4GB if you use an UNSIGNED LONG) limit to store that string length). Since some folks (like soniaa in the Dim A thread) need to access larger sizes than that, an INTEGER64 would probably need to be used to stop any issues and work for future expansion, so you'd probably have to add 8 bytes per string...
Say what??
Using a special mark like end of string is a procedural solution. The right issue noted by Steve can be minimized using a big mark as EOF (a sequence of 4-8 byte),so we change the case of premature end of string rare but not impossible.
TYPE
FirstString AS STRING
SecondString AS STRING
ThirdString AS STRING
END TYPE
CONST FirstString = 1, SecondString =2, ThirdString = 3
DIM ArrayString (FirstString TO ThirdString) AS STRING
kind of along the same lines I was wondering if you could use an array in a type variable something likeThat's on the cards as the next thing to work on
type a
b(20) as integer
c as string * 5
end type
kind of along the same lines I was wondering if you could use an array in a type variable something likeThat's on the cards as the next thing to work on
type a
b(20) as integer
c as string * 5
end type