Coder's Guild Mailing List

Re: Visual Basic Strings

Posted by Bernie Siegrist on 1999-08-12

Date: Tue, 10 Aug 1999 21:40:04 +0500
From: "Muhammad Ali Shah" <mashah@xxxxx.xxx.xx>


>3. Why can't I read/write data to a file with the following structure
>TYPE employee
>   dim name as string
>   dim age as integer
>END TYPE
>If however, I use fiexed length strings, the read/write functions do exactly
>what they are intended.

I'd say your "String" is null-terminated. This means what you declare as
"string" is only a pointer to a null-terminated array of chars. So if you
write this to a file you either only write the pointer or you get an error
(depending on the compiler). If you define a fixed-length string it's a
Pascal style string, i.e. an array of char (not a pointer!) with the first
byte indicating the length. So...

String[20] or String * 20 (?): Array of chars; first byte = length
String = POINTER to array of chars; last byte = 0

Questions? *g