Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Assert like macros

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin/PBCC Assert like macros

    A generous use of these will help pinpoint any problems.

    update: added some Tix macros to find CPU hogs (page 2)

    update #2: added Class Error Macros (page 3)
    - exit Method or Property
    - print debug message - only show in debug mode
    - set Class error flag
    - set Class error message

    Code:
    [FONT=Times New Roman]'pb 4,5 ~ 8,9[/FONT]
    [FONT=Times New Roman]'DebugExit.inc[/FONT]
    [FONT=Times New Roman]'[/FONT]
    [FONT=Times New Roman]'the evaluation isn't done inside parentheses (test) - PB's short circuit evaluation works as expected[/FONT]
    [FONT=Times New Roman]'procedure = Sub, Function, Method; whatever type of procedure macro used in[/FONT]
    [FONT=Times New Roman]'Function GetThis(ByVal x As Long) As Long[/FONT]
    [FONT=Times New Roman]'    ErrExitFalse(x, Function, "x = null")[/FONT]
    [FONT=Times New Roman]'    'rest of code ...[/FONT]
    [FONT=Times New Roman]'End Function[/FONT]
    [FONT=Times New Roman]'[/FONT]
    [FONT=Times New Roman]'   if x = 0 and in Debug mode; message gets printed[/FONT]
    [FONT=Times New Roman]'       "GETTHIS: x = null"[/FONT]
    [FONT=Times New Roman]'   if not in Debug mode - just exits the Function[/FONT]
    [FONT=Times New Roman]'[/FONT]
    [FONT=Times New Roman]'ErrExitTrue(IsNothing(MyObj), Method, "MyObj failed")[/FONT]
    [FONT=Times New Roman]'[/FONT]
     
    [FONT=Times New Roman]Macro ErrExitFalse(test, procedure, msg)[/FONT]
    [FONT=Times New Roman]'exit procedure if test = False[/FONT]
    [FONT=Times New Roman]'   print Debug message (only prints in Debug mode)[/FONT]
    [FONT=Times New Roman]'[/FONT]
    [FONT=Times New Roman]'   this avoids using parentheses: (test) = %FALSE : PB's short circuit evaluation works as expected[/FONT]
    [FONT=Times New Roman]'[/FONT]
    [FONT=Times New Roman]If test Then[/FONT]
    [FONT=Times New Roman]Else[/FONT]
    [FONT=Times New Roman]   #Debug Print FuncName$ +": "+ msg[/FONT]
    [FONT=Times New Roman]   Exit procedure[/FONT]
    [FONT=Times New Roman]End If[/FONT]
    [FONT=Times New Roman]End Macro[/FONT]
    [FONT=Times New Roman]Macro ErrExitTrue(test, procedure, msg)[/FONT]
    [FONT=Times New Roman]'exit procedure if test = True[/FONT]
    [FONT=Times New Roman]'   print Debug message (only prints in Debug mode)[/FONT]
    [FONT=Times New Roman]If test Then[/FONT]
    [FONT=Times New Roman]   #Debug Print FuncName$ +": "+ msg[/FONT]
    [FONT=Times New Roman]   Exit procedure[/FONT]
    [FONT=Times New Roman]End If[/FONT]
    [FONT=Times New Roman]End Macro[/FONT]
    [FONT=Times New Roman]Macro ErrGoFalse(test, MARKER, msg)[/FONT]
    [FONT=Times New Roman]'GoTo MARKER: if test = False[/FONT]
    [FONT=Times New Roman]'   print Debug message (only prints in Debug mode)[/FONT]
    [FONT=Times New Roman]If test Then[/FONT]
    [FONT=Times New Roman]Else[/FONT]
    [FONT=Times New Roman]   #Debug Print FuncName$ +": "+ msg[/FONT]
    [FONT=Times New Roman]   GoTo MARKER[/FONT]
    [FONT=Times New Roman]End If[/FONT]
    [FONT=Times New Roman]End Macro[/FONT]
    [FONT=Times New Roman]Macro ErrGoTrue(test, MARKER, msg)[/FONT]
    [FONT=Times New Roman]'GoTo MARKER: if test = True[/FONT]
    [FONT=Times New Roman]'   print Debug message (only prints in Debug mode)[/FONT]
    [FONT=Times New Roman]If test Then[/FONT]
    [FONT=Times New Roman]   #Debug Print FuncName$ +": "+ msg[/FONT]
    [FONT=Times New Roman]   GoTo MARKER[/FONT]
    [FONT=Times New Roman]End If[/FONT]
    [FONT=Times New Roman]End Macro[/FONT]
    Last edited by Stanley Durham; 1 Aug 2009, 01:27 PM.
    stanthemanstan~gmail
    Dead Theory Walking
    Range Trie Tree
    HLib ~ Free Data Container Lib ~ Arrays, Lists, Stacks, Queues, Deques, Trees, Hashes

  • #2
    put StartTix at top of all procedures
    put EndTix and bottom of all procedures
    run in debug mode
    spot all CPU hogs right away

    you can the move the StartTix macro down to see which line of code is hogging CPU

    Code:
     
    Macro StartTix = Local qTix_Counter As Quad : Tix qTix_Counter
    Macro EndTix
        Tix End qTix_Counter
        #Debug Print FuncName$ +": Tix = "+ Format$(qTix_Counter, "#,")
    End Macro
    stanthemanstan~gmail
    Dead Theory Walking
    Range Trie Tree
    HLib ~ Free Data Container Lib ~ Arrays, Lists, Stacks, Queues, Deques, Trees, Hashes

    Comment


    • #3
      Code:
      'ClassErr.inc
          '
          '   error handling macros
          'IMPORTANT!
          '   all classes have to have the SAME error flag & error message string variables
          '
          '   change to suit you're style of programming
      Macro McClassErrFlag = mErr     'LONG - error flag variable
      Macro McClassErrStr = mErrMsg   'STRING - error message string
      Macro MExitFalse(test, msg)
          'Exit Method if test = False
          '   set error flag True
          '   set error message
          '   print Debug error
          If test Then
          Else
              McClassErrFlag = 1
              McClassErrStr = msg
              #Debug Print FuncName$ +": "+ msg
              Exit Method
          End If
      End Macro
      Macro PExitFalse(test, msg)
          'Exit Property if test = False
          '   set error flag True
          '   set error message
          '   print Debug error
          If test Then
          Else
              McClassErrFlag = 1
              McClassErrStr = msg
              #Debug Print FuncName$ +": "+ msg
              Exit Property
          End If
      End Macro
      Macro MExitTrue(test, msg)
          'Exit Method if test = True
          '   set error flag True
          '   set error message
          '   print Debug error
          If test Then
              McClassErrFlag = 1
              McClassErrStr = msg
              #Debug Print FuncName$ +": "+ msg
              Exit Method
          End If
      End Macro
      Macro PExitTrue(test, msg)
          'Exit Property if test = True
          '   set error flag True
          '   set error message
          '   print Debug error
          If test Then
              McClassErrFlag = 1
              McClassErrStr = msg
              #Debug Print FuncName$ +": "+ msg
              Exit Property
          End If
      End Macro
      Macro GoFalse(test, msg, MARKER)
          'GOTO MARKER if test = False
          '   set error flag True
          '   set error message
          '   print Debug error
          If test Then
          Else
              McClassErrFlag = 1
              McClassErrStr = msg
              #Debug Print FuncName$ +": "+ msg
              GoTo MARKER
          End If
      End Macro
      Macro GoTrue(test, msg, MARKER)
          'GOTO MARKER if test = True
          '   set error flag True
          '   set error message
          '   print Debug error
          If test Then
              McClassErrFlag = 1
              McClassErrStr = msg
              #Debug Print FuncName$ +": "+ msg
              GoTo MARKER
          End If
      End Macro
      stanthemanstan~gmail
      Dead Theory Walking
      Range Trie Tree
      HLib ~ Free Data Container Lib ~ Arrays, Lists, Stacks, Queues, Deques, Trees, Hashes

      Comment

      Working...
      X