Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



Using Breakpoints to Troubleshoot


As mentioned, a breakpoint is a point at which Access will unconditionally halt the execution of code. You can set multiple breakpoints in your code. You can add and remove breakpoints as your code executes.

A breakpoint enables you to halt your code execution at a suspicious area of code. This enables you to examine everything that is going on at that point in your code execution. By strategically placing breakpoints in your code, you quickly can execute sections of code that you already debugged, stopping only at problem areas.

To set a breakpoint, follow these steps:


  • Place your cursor on the line of code where you want to invoke the debugger.

  • You can insert a breakpoint in one of four ways:

    • Press your F9 function key.

    • Click in the gray margin area to the left of the line of the code that will contain the breakpoint.

    • Click the Toggle Breakpoint button on the Debug toolbar.

    • Choose Debug, Toggle Breakpoint.


    The line of code containing the breakpoint appears in a different color, and a dot appears, indicating the breakpoint.

  • Run the form, report, or module containing the breakpoint. VBA suspends execution just before executing the line of code where you placed the breakpoint. The statement that is about to execute appears in a contrasting color (the default is yellow).


  • Now that you have suspended your code, you can step through it one line at a time, change the value of variables, and view your call stack, among other things.

    Keep in mind that a breakpoint is actually a toggle. If you want to remove a breakpoint, click in the gray margin area, press F9, or click Toggle Breakpoint on the Debug toolbar. Access removes breakpoints when you close the database, when you open another database, or when you exit Access.

    It is easiest to get to know the debugger by actually using it. The following example gives you hands-on experience in setting and stopping code execution at a breakpoint. The example is developed further later in the chapter.

    Start by creating a form called frmDebug that contains a command button called cmdDebug. Give the button the caption Start Debug Process. Place the following code in the Click event of the command button:

    Sub cmdDebug_Click ()
    Call Func1
    End Sub

    Create a module called basFuncs. Enter three functions into the module:

    Sub Func1 ()
    Dim intTemp As Integer
    intTemp = 10
    Debug.Print "We Are Now In Func1()"
    Debug.Print intTemp
    Call Func2
    End Sub
    Sub Func2 ()
    Dim strName As String
    strName = "Bill Gates"
    Debug.Print "We Are Now In Func2()"
    Debug.Print strName
    Call Func3
    End Sub
    Sub Func3 ()
    Debug.Print "We Are Now In Func3()"
    MsgBox "Hi There From The Func3() Sub Procedure"
    End Sub

    Now you should debug. Start by placing a breakpoint within the Click event of cmdDebug on the line called Call Func1. Here are the steps:


  • Click anywhere on the line of code that says Call Func1.

  • Click in the gray margin area, press the F9 function key, click the Toggle Breakpoint button on the Debug toolbar, or choose Debug, Toggle Breakpoint. The line with the breakpoint turns a different color (red by default).

  • Go into Form view and click the Start Debug Process button. Access suspends execution just before executing the line where you placed the breakpoint. VBA displays the line that reads Call Func1 in a different color (by default, yellow), indicating that it is about to execute that line (see Figure 15.6).

    Figure 15.6. Code execution is halted at a breakpoint.



  • / 544