Microsoft KB Archive/42666
Article ID: 42666
Article Last Modified on 11/21/2006
This article was previously published under Q42666
This article describes a case where a syntax error in the filename for an OPEN statement gives "Type Mismatch" in the environment and a different (but more informative) message, "String Expression Required," in BC.EXE. This is a design limitation.
The following program line causes the QB.EXE environment of QuickBasic to highlight "LEN = 20" and issue the error message "Type Mismatch." Under the QBX.EXE environment of Microsoft Basic PDS 7.00, "FILE.DAT" is highlighted when the "Type Mismatch" error occurs:
OPEN FILE.DAT FOR RANDOM AS #1 LEN = 20
"Type Mismatch" occurs because a string variable was expected instead of FILE.DAT, which is by default a single-precision variable.
The BC.EXE compiler instead identifies this syntax error as "String Expression Required" and points to the "T" in FILE.DAT.
This information applies to QB.EXE in QuickBasic Versions 4.00, 4.00b, and 4.50, to QB.EXE in Microsoft Basic Compiler Versions 6.00 and 6.00b, and to QBX.EXE in Microsoft Basic PDS Version 7.00 for MS-DOS.
QuickBasic Versions 2.00, 2.10, and 3.00 issue the "String Expression Required" message in both the environment and the separate compilation method.
The following is the necessary correction to follow proper syntax:
OPEN "FILE.DAT" FOR RANDOM AS #1 LEN = 20
Additional query words: QuickBas BasicCom