PRB: "Bad Filename" When Use COM2: Without COM1: Installed (23413)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b

This article was previously published under Q23413
3.00 4.00 4.00b 6.00 MS-DOS kbprg kbprb

SYMPTOMS

QuickBasic programs give a "Bad Filename" error on the OPEN COM2: statement if COM1: is unavailable in the system as a device.

CAUSE

QuickBasic does not allow the use of the second communications port (COM2:) if the first port (COM1:) is unavailable.

RESOLUTION

Below is a program that works around this behavior.

STATUS

This behavior is by design.

MORE INFORMATION

QuickBasic looks in the BIOS data area at RS232_BASE. This area stores the addresses of up to four communications ports.

When you start your system, the BIOS initialization code checks for serial ports, puts in the address of any it finds, and sets the rest of the locations to zero. When both COM1: and COM2: are present, the address of COM1: (3f8h) is in the first word of RS232_BASE. The address of COM2: (2f8h) is in the second word.

However, when COM2: is the only port installed, 2f8h is in the first word and the second word is zero. When QuickBasic is loaded, it looks at RS232_BASE to see what serial ports are present, but it only recognizes COM2: when it is in the second word.

The following program patches the second word of RS232_BASE with the address of COM2:. The program must be run before the QuickBasic application that uses COM2:. If you put this code at the beginning of your program, it will be executed too late because QuickBasic checks for serial ports before starting your first Basic statement.

The program is as follows:
   DEF SEG=&h0040
   IF (PEEK(0) + 256*PEEK(1))=&h02f8 THEN
     POKE 2,&hf8 : POKE 3,&h02
     PRINT "COM2 PATCH MADE"
   ELSE
     PRINT "COM2 PATCH NOT MADE"
   END IF
   END
				

REFERENCES

Portions of this article were taken from the "Microsoft Systems Journal," May 1987, Volume 2.

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB23413