No announcement yet.

Macro for checking Program logic & Errors

  • Filter
  • Time
  • Show
Clear All
new posts

    Macro for checking Program logic & Errors

    With all the latest chatter regarding program errors, Tracing, etc. I decided to write a Macro just for that:

    ' I #Include it so variables remain consistent across programs  
    ' If #Including, place #Include line wherever Macros are defined 
       ' for example my Include line is:
    ' #Include "C:\Power Basic\Includes\" 
     'The variables Chk$ & Check_File_Num& may be initialized Local or Global
     'g_Chk_Print_Flag MUST be Global
     'Destination Folder may need to be reset and/or 
     '       log name changed  
         'typical call: {Change 001 & Using$ to whatever appropriate}
     'chk$ = using$("at 001 x = #   y = #", x, y): m_Check
    ' Obviously the variable names may be changed to suit your programming
    '   conventions. I try to keep them descriptive and short for myself.
    Macro m_Check
     Incr g_Chk_Print_Flag 'keeps track to Open or Append the log file
     Check_File_Num = FreeFile
     If g_Chk_Print_Flag = 1 Then 'first time through
        Open "C:\Temp\Track_Log.txt" For Output As #Check_File_Num 
          'You may want to put mor infor in this line
        Print #Check_File_Num, , Date$ & " " & Time$
       Else 'subsequent runs 
        Open "C:\Temp\Track_Log.txt" For Append As #Check_File_Num ' hopefully not a conflict
     End If       
     If Err Then ' in case Error tripped
        chk$ = chk$ & _
               Using$("    Error ### ", Err) & Error$(Err) 
        ErrClear 'Reset for next time called
     End If        
     Print #Check_File_Num, Chk$ & " in " & FuncName$ 
     Close #Check_File_Num 'insures file is written to disk and not cached
      Reset Chk$ 'ready for next time here
    End Macro
    It's a pretty day. I hope you enjoy it.


    JWAM: (Quit Smoking):
    LDN - A Miracle Drug: