SHELL Statement Loses Current Data in Serial Port Input Buffer (37417)






This article was previously published under Q37417

SYMPTOMS

A SHELL statement will empty the input buffer (thus losing data) of the currently opened serial communications port (COM1 or COM2).

STATUS

Microsoft has confirmed this to be a bug in Microsoft QuickBasic versions 4.00, 4.00b, and 4.50; in Microsoft Basic Compiler versions 6.00 and 6.00b (buglist6.00, buglist6.00b); and in Microsoft Basic Professional Development System (PDS) version 7.00 (buglist7.00).

This problem is corrected in Microsoft Basic PDS 7.10 (fixlist7.10) if you compile with BC /O or run in the QBX.EXE environment. However, if you compile your program in 7.10 to use the BRT71xxx.EXE run-time module (in other words, you don't compile with BC /O), you will still lose data in the communications input buffer because the support for communications is in the run-time module, and the run-time module is released from memory during a SHELL to make more room for other programs to load. This is not a problem; it is a design limitation.

To work around the problem, empty the buffer (such as with the INPUT$ statement) before invoking the SHELL statement to retain information that would have been lost.

MORE INFORMATION

The following steps reproduce the behavior:

  1. Open a serial port (COM1 or COM2).
  2. Allow the buffer to be filled.
  3. Using the LOC function, print out the number of bytes in the buffer.
  4. Execute the SHELL statement with any valid parameter (such as SHELL "DIR").
  5. Using the LOC function again, print out the number of bytes in the buffer. This number will be 0 (zero).
The following code will reproduce the above behavior. (Please note that the size of the buffer after the SHELL statement will be 0.)
   OPEN "com1:9600" FOR RANDOM AS #1
   ' This loop will allow data to begin flowing into COM1.
   ' The loop terminates when an ESC key is pressed.
   DO UNTIL INKEY$ = CHR$(27)
   LOOP
   PRINT "Size of buffer before SHELL statement: ", LOC(1)
   PRINT
   PRINT "press any key to shell"
   WHILE (INKEY$ = ""): WEND
   SHELL "dir"
   PRINT "Size of buffer after SHELL statement: ", LOC(1)
   CLOSE
				

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: KB37417