Microsoft KB Archive/37483

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


CHAIN "RETURN Without GOSUB" When Using ON ERROR GOTO & No /O

Article ID: 37483

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b



This article was previously published under Q37483

SUMMARY

When chaining from a program that does not trap errors (ON ERROR GOTO) to a program that does, a "RETURN without GOSUB" error message can appear. This occurs only when the programs are compiled requiring the run-time library BRUN4x.EXE.

Because the run-time system is initialized in the first program, you need to compile both programs with BC /E to support error trapping.

Another way to avoid this problem is to compile both programs with BC /O to make them stand alone. With this process, the chaining program does not require compiling with /E.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50 and to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2. The code below does not generate the error described above with Microsoft Basic PDS Version 7.00.

MORE INFORMATION

The programs below, when compiled without /O, will give the "RETURN without GOSUB" run-time error message in the second program.

Code Examples

The first program is as follows:

' TEST.BAS
      CHAIN "test1"
      END
                

The second program is as follows:

' TEST1.BAS
      ON ERROR GOTO 0
      K% = 1
      ON K% GOSUB handle
      END
                

handle:

      A$ = INKEY$: IF A$ = "" THEN GOTO handler
      RETURN
                


Additional query words: QuickBas BasicCom

Keywords: KB37483