Microsoft KB Archive/39587

= QB Advisor 4.50 &quot;Help: ON ERROR Statement Details&quot; Correction =

Article ID: 39587

Article Last Modified on 11/21/2006



This article was previously published under Q39587



SUMMARY
The paragraph in the QuickBasic Version 4.50 QB Advisor (on-line help facility) that describes how to perform error trapping in a SUB or FUNCTION procedure or DEF FN function is incorrect, and an incorrect example is shown.

The paragraph incorrectly states that a SUB, FUNCTION, or DEF FN block can contain an error-handling routine. The error handler-label and RESUME must be at the main-program level or module level.



MORE INFORMATION
The &quot;Help: ON ERROR Statement Details&quot; should instead say the following:

To have an error-handling routine trap errors occurring within a SUB, FUNCTION, or DEF FN block, you need to place the error- handling routine at the module-level code (before the SUB or FUNCTION procedure definition). A label (such as Labelx) marks the start of the error-handler routine. The ON ERROR GOTO Labelx statement must be an executable statement within the same module as Labelx, but Labelx is put OUTSIDE the SUB...END SUB or FUNCTION...END FUNCTION procedure block, and the ON ERROR GOTO Labelx statement can be put INSIDE the procedure block or main program.

Note: QuickBasic Version 4.50 uses global-error handling. For more information about global-error handling, please search for &quot;GLOBAL&quot;, &quot;ERROR&quot;, &quot;HANDLING&quot;, and &quot;4.50&quot; in this KnowledgeBase.

The following program correctly demonstrates the flow of control when an error occurs in a SUB procedure: DECLARE SUB dork CALL dork PRINT &quot;This is the last statement in main module&quot; END handler: PRINT &quot;error 50 has occurred&quot; RESUME NEXT

SUB dork ON ERROR GOTO handler ERROR 50             'This forces an error to occur PRINT &quot;In the subroutine&quot; END SUB You can find the incorrect paragraph in the QB Advisor &quot;Help: ON ERROR Statement Details,&quot; as follows:

 Run QB.EXE Version 4.50. Press SHIFT+F1 to invoke the QB Advisor Help menu. Select Index. Press PAGE DOWN key, or press O to jump directly to the Keywords beginning with the letter &quot;O&quot;, then cursor to the ON ERROR statement and select it. Select Details. The following window title appears:

&quot;Help: ON ERROR Statement Details&quot;

 Scroll down to the seventh paragraph. This paragraph and the example program below contain errors.</ol>

The following is the INCORRECT paragraph and example that can be found in the HELP facility:

&quot; [ The following information is in error: ] SUB and FUNCTION procedures and DEF FN functions can contain their own error handlers. The error handler must be located after the last executable statement but before the END SUB, END FUNCTION, or END DEF statement. To keep the error handler from executing when there is no error, the procedure or function must terminate with an EXIT SUB, EXIT FUNCTION, or EXIT DEF statement immediately ahead of the error handler, as in the following example:

SUB InitializeMatrix (var1, var2, var3, var4) .     .   ON ERR GOTO ErrorHandler    ' [ Should be ON ERROR, not ON ERR! ]     .      .   EXIT SUB         ' [ EXIT SUB is optional (not required). ]

ErrorHandler:   ' [ Must move this after END SUB !] .     .   RETURN           ' [ Use RESUME, not RETURN! Must move '  ErrorHandler...RESUME to after END SUB ]

END SUB [ end of incorrect HELP example. ] &quot;

Additional query words: QuickBas

Keywords: KB39587

-

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

© Microsoft Corporation. All rights reserved.