Microsoft KB Archive/35245

From BetaArchive Wiki
Knowledge Base

Fixed-Length Strings Are Initialized to NULL (0), Not Blanks

Article ID: 35245

Article Last Modified on 11/21/2006

This article was previously published under Q35245


The information below about fixed-length string arrays should be inserted in the following manuals:

  1. "Microsoft QuickBasic 4.0: Basic Language Reference"
  2. "Microsoft Basic Compiler 6.0: Basic Language Reference" for Versions 6.00 and 6.00b for MS OS/2 and MS-DOS

On Pages 156, 174, and 352, under the DIM, ERASE, and REDIM statements, the above manuals state that elements of string arrays are initialized to null strings (strings of zero length). However, this is not the case with fixed-length strings. Fixed-length strings are initialized as a string of null bytes (with ASCII value of 0). The LEN function always returns the complete length of the fixed-length string. If a fixed-length string is initialized to "" (the null string), it is completely filled with blank spaces (ASCII value of 32).


This documentation error was corrected in the QuickBasic 4.50 and Microsoft Basic PDS 7.00 documentation.

The following is a code example:

c$ = CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0)
PRINT "j is printed between the stars:  *"; j; "*"
PRINT "j looks like a string of blanks, but it's not."
IF j = c$ THEN PRINT "j equals CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0)."
IF j <> "" THEN PRINT "j does not equal "; CHR$(34); CHR$(34);
IF j <> "    " THEN PRINT " or "; CHR$(34); "    "; CHR$(34); "."
PRINT "But if I set j to "; CHR$(34); CHR$(34);
j = ""
IF j = "    " THEN
   PRINT " then j will equal "; CHR$(34); "    "; CHR$(34); "."

The following is the output from the program above:

j is printed between the stars:  *    *
j looks like a string of blanks, but it's not.
j equals CHR$(0) + CHR$(0) + CHR$(0) + CHR$(0).
j does not equal "" or "    ".
But if I set j to "" then j will equal "    ".

Additional query words: QuickBas BasicCom

Keywords: KB35245