Microsoft KB Archive/37029

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


"Invalid Constant" Using Variable for Length of Fixed String

Article ID: 37029

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Professional Development System 7.0



This article was previously published under Q37029

SUMMARY

The length of a fixed-length character string variable must be specified as a integer constant or as a CONST integer constant. The run-time error "Invalid Constant" results if the number in a "STRING * number" clause of a DIM or REDIM statement is a variable, or a constant of a non-integer type.

The length of a fixed-length string must not be negative. A fixed-length string must have a length of at least one.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2.

MORE INFORMATION

QuickBasic versions earlier than Version 4.00 do not support fixed-length string variables.

The following is a code example:

'This program will correctly give "Invalid Constant" when x is replaced
'by y or z in the DIM statement.
   DEFINT A-Z
   CONST x = 11
   CONST y = 11.0
   z = 11
   DIM a AS STRING * x
   a = "hello there"
   PRINT a
   END
                


Additional query words: QuickBas BasicCom

Keywords: KB37029