"Invalid Constant" Using Variable for Length of Fixed String (37029)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 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
				

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB37029