Microsoft KB Archive/42665

= &quot;Bad Record Length&quot; GET#n,,x$ Variable-Length String from File =

Article ID: 42665

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBASIC 4.0b, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBasic 4.5 for MS-DOS, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q42665



SUMMARY
The run-time error &quot;Bad record length&quot; occurs when a QuickBasic Version 4.00b or 4.50 program uses a variable-length string as the third argument in a GET statement to input a string that was PUT in the file as a fixed-length string. This information also applies to Microsoft Basic Compiler Version 6.00b for MS-DOS and MS OS/2 and Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2.

No error occurs in QuickBasic Version 4.00 or Basic compiler Version 6.00 because these earlier versions don't expect a 2-byte string length when you input a variable-length string as the third argument of the GET statement. For a related article discussing PUT, query on the following words in this Knowledge Base:

BAD RECORD LENGTH and PUT

When reading from a random file that was created using fixed-length strings, you should GET them using fixed-length strings also.



MORE INFORMATION
The &quot;Details&quot; listed under &quot;GET&quot; in the QuickBasic 4.50 QB Advisor on-line Help system misleadingly suggest using a variable-length string in the following manner: VarStrings$ = STRING$(10, &quot; &quot;) GET #1,, VarString$ This method works in QuickBasic Version 4.00, but not in Versions 4.00b or 4.50.

To avoid the &quot;Bad record length&quot; error message, use a fixed-length string in your GET statement or create the file using a variable-length string in QuickBasic 4.00b or 4.50, Basic compiler 6.00b, or Basic PDS 7.00. (Making the variable-length string 2 bytes longer than the original string does not correct the problem.)

The following code fragment works without error in QuickBasic Version 4.00 or Basic compiler 6.00, but gives a &quot;Bad record length&quot; error in QuickBasic 4.00b or 4.50, Basic compiler 6.00b, or Basic PDS 7.00: REM This fragment places information in a file. REM It prompts for 8 strings to be placed in a fixed-length REM string &quot;a&quot; and then PUT into file #1

OPEN &quot;afile.dat&quot; FOR RANDOM AS #1 LEN = 80 DIM a AS STRING * 80 FOR i = 1 TO 8 INPUT a PUT #1,, a NEXT i CLOSE #1

REM This fragment reads in the data from the file and echoes to the REM screen. The strings are retrieved using the statements listed REM under &quot;GET&quot; under the &quot;Details&quot; on-line Help hyperlink. REM To fix the problem, make VarString$ a fixed-length string REM with DIM VarString as string * 80, to replace the STRING$ REM statement

OPEN &quot;afile.dat&quot; FOR RANDOM AS #1 LEN = 80 VarStrings$ = STRING$(10, &quot; &quot;) FOR i = 1 TO 8 GET #1,, VarString$    'this line will give error message PRINT VarString$ NEXT i CLOSE #1

Additional query words: QuickBas BasicCom

Keywords: KB42665

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.