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:
    'pb 4,5 ~ 8,9
    'DebugExit.inc
    '
    'the evaluation isn't done inside parentheses (test) - PB's short circuit evaluation works as expected
    'procedure = Sub, Function, Method; whatever type of procedure macro used in
    'Function GetThis(ByVal x As Long) As Long
    '    ErrExitFalse(x, Function, "x = null")
    '    'rest of code ...
    'End Function
    '
    '   if x = 0 and in Debug mode; message gets printed
    '       "GETTHIS: x = null"
    '   if not in Debug mode - just exits the Function
    '
    'ErrExitTrue(IsNothing(MyObj), Method, "MyObj failed")
    '
     
    Macro ErrExitFalse(test, procedure, msg)
    'exit procedure if test = False
    '   print Debug message (only prints in Debug mode)
    '
    '   this avoids using parentheses: (test) = %FALSE : PB's short circuit evaluation works as expected
    '
    If test Then
    Else
       #Debug Print FuncName$ +": "+ msg
       Exit procedure
    End If
    End Macro
    Macro ErrExitTrue(test, procedure, msg)
    'exit procedure if test = True
    '   print Debug message (only prints in Debug mode)
    If test Then
       #Debug Print FuncName$ +": "+ msg
       Exit procedure
    End If
    End Macro
    Macro ErrGoFalse(test, MARKER, msg)
    'GoTo MARKER: if test = False
    '   print Debug message (only prints in Debug mode)
    If test Then
    Else
       #Debug Print FuncName$ +": "+ msg
       GoTo MARKER
    End If
    End Macro
    Macro ErrGoTrue(test, MARKER, msg)
    'GoTo MARKER: if test = True
    '   print Debug message (only prints in Debug mode)
    If test Then
       #Debug Print FuncName$ +": "+ msg
       GoTo MARKER
    End If
    End Macro
    Last edited by Stanley Durham; 1 Aug 2009, 02: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