Microsoft KB Archive/41390

= Handling Events and ERRORs When Basic Calls Non-Basic Routines =

Article ID: 41390

Article Last Modified on 8/16/2005

-

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
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q41390



SUMMARY
This information applies to QuickBasic Versions 4.00, 4.00b, and 4.50, Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and OS/2, and Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2.

The following corrections for documentation errors apply to Page 296 of the learning and using Microsoft QuickBasic manual for QuickBasic 4.00 and 4.00b and Basic compiler 6.00 and 6.00b, and to Page 442-443 of the &quot;Microsoft Basic Version 7.0: Programmer's Guide&quot; for Basic PDS 7.00:


 * 1) The section &quot;Events and Errors&quot; incorrectly implies that Basic can call a subroutine written in a different language, have that language sense an EVENT or ERROR, and then jump to the error handling routine in Basic. Basic is not designed to do this. What happens is that the first event (but not subsequent events) that occurs during the other language procedure is stored on the stack until control returns to Basic. If the other language procedure calls a Basic procedure in which the ERROR statement forces an error (or a natural error occurs), then the error handler (if any) in the Basic program handles the error and RESUMEs as described below.
 * 2) The last sentence is incorrect (&quot;The Basic statement containing... is the statement that RESUME would reexecute&quot;). This sentence should be changed to say the following:

&quot;The Basic statement containing the error (ERROR x%) is the statement that RESUME would reexecute. RESUME NEXT would reexecute at the following statement.&quot;



MORE INFORMATION
The program shown below is an example of a Basic program calling a C function that calls a Basic procedure. The program, as written, will loop indefinitely between the error-handling routine and the Basic subprogram that generates the error. If the RESUME statement is changed to RESUME NEXT, the program executes the next statement in the subprogram: PRINT &quot;Return from ERROR&quot;.

(The documentation incorrectly states that &quot;The Basic statement containing the call to the non-Basic code is the statement that RESUME would reexecute.&quot; According to this statement, the CALL CSUB statement would be executed; however, execution actually returns to the Basic subprogram where the error occurred, as described above.)

The following is a code example: REM ** Here is the Basic program

DECLARE SUB jump DECLARE SUB csub CDECL CLS ON ERROR GOTO errhand FOR i = 1 TO 5 PRINT &quot; Before call to c &quot;, FRE(-2) CALL csub PRINT &quot; out if c:&quot;, FRE(-2) NEXT PRINT &quot;At end &quot;, FRE(-2) END errhand: PRINT &quot; error handle => &quot;, FRE(-2) RESUME SUB jump print &quot; Generate and Error&quot; ERROR 9 print &quot;Return from ERROR &quot; END SUB extern void fortran jump(void);

void csub(void) {  jump; }

Additional query words: QuickBas BasicCom

Keywords: KB41390

-

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

© Microsoft Corporation. All rights reserved.