errors and debugging l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Errors and Debugging PowerPoint Presentation
Download Presentation
Errors and Debugging

Loading in 2 Seconds...

play fullscreen
1 / 15

Errors and Debugging - PowerPoint PPT Presentation


  • 221 Views
  • Uploaded on

Errors and Debugging . Learn how to make errors. Syntax Compile Run-time Semantic. Cn’t type Can’t rememb Can’t decide Can’t think. Intercept Errors Before VBA. Utilities must have error handling Anticipate errors in important components On Error GoTo Resume ExitStageLeft.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Errors and Debugging' - paul2


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
learn how to make errors
Learn how to make errors
  • Syntax
  • Compile
  • Run-time
  • Semantic
  • Cn’t type
  • Can’t rememb
  • Can’t decide
  • Can’t think
intercept errors before vba
Intercept Errors Before VBA
  • Utilities must have error handling
  • Anticipate errors in important components
  • On Error GoTo
  • Resume ExitStageLeft
on error whaaaat
On Error, whaaaat?
  • On Error Goto 0
    • Disables the error handler
  • On Error Resume Next
    • Ignore the error and continue
  • On Error Goto Label
    • Jump to Label: for your own code to handle
polishing off your resume
Polishing off your Resume
  • Resume
    • Suggested only for run-time debugging!!
  • Resume Next
    • Just keep on running after error detected, don’t report the error at all.
  • Resume Label
    • Best. Go to Label: when error detected
trap for the usual suspects
Trap for the “Usual suspects”

Here is where your own code can handle the errors

  • If you know division by zero is possible
    • If Err.Number = 11 Then yadda yadda
  • If you know data type can be wrong
    • If Err.Number = 13 Then yadda yadda
  • How to know Err.Number?

MsgBox Err.Number & ": " & Err.Description

Resume Exit_Label

vba run time error objects
VBA Run-time Error Objects
  • Trap-able
  • Err object
  • Err.Number
  • Err.Description
  • Err.Source (MSAccess)
custom traps
Custom Traps
  • Prevent user errors by making them yourself
  • If not IsDate(dteUser) Then _ Err.Raise 32001
  • If not IsNumeric(varUser) Then _

Err.Raise 32002

  • Err.Raise can promote errors to calling Procs.
form level errors
Form-level Errors
  • In Form event “OnError”
  • Assignment2.mdb
  • Response arg controls Access err msgs

acDataErrContinue (override err msgs)

acDataErrDisplay (allow err msgs)

  • Issue your own err msgs:

If ActiveControl.Name = "txtDate" then…

If ActiveControl.Name = "cboParty" then…

compile time errors
Compile-time errors
  • Occur before run-time errors
  • Find these on purpose
  • Menu selections: Debug, Compile
ado run time error collection
ADO Run-time error collection
  • Trap-able
  • Can be same error numbers as VBA
  • When same, error belongs to ADO
  • Useful in debugging linked tables
  • Useful in client-server situations
  • Example: frmErrorHandling
    • Sub ShowErrors()
when are errors reported
When are errors reported?
  • Sometimes, when they are caused
  • Sometimes, where they are caused
  • Error handling routine chained back to callers
  • “Resume” can be dangerous in chains
  • Best to trap in individual Procs… unless…

Subordinate procs return errors for supervisor Proc

debugging
Debugging
  • Calm demeanor is essential
  • Take a totally objective view
  • “What does this statement do?” (right!)
  • “What should this statement do?” (wrong!)
  • Cardinal rule: get more information
techniques
Techniques
  • Break points, F8
  • Hover
  • Run to cursor
  • Watch, QuickWatch
  • Run and Re-run lines of code
design time tools
Design-time tools
  • Bulk commenting
  • Bookmarking source