Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #2407

Re: MS Excel COMAddins Manager VB6 app

From Arne Saknussemm <idm.10.arnsak@mamber.net>
Newsgroups comp.lang.basic.visual.misc, microsoft.public.vb.general.discussion
Subject Re: MS Excel COMAddins Manager VB6 app
Date 2019-12-06 09:29 +0100
Organization org
Message-ID <20191206092928.000051c8@eternal-september.org> (permalink)
References (1 earlier) <20191204094658.00002584@eternal-september.org> <qsat3n$9fs$1@dont-email.me> <20191205143625.00006dd2@eternal-september.org> <20191205144658.00006d26@eternal-september.org> <qsbr1c$879$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


:: On Thu, 05 Dec 2019 15:58:16 -0500
:: (comp.lang.basic.visual.misc,microsoft.public.vb.general.discussion)
:: <qsbr1c$879$1@dont-email.me>
:: GS <gs@v.invalid> wrote:


> > https://docs.microsoft.com/en-us/sysinternals/downloads/debugview

> > '
> > ====================================================================
> > Private Declare Sub OutputDebugString Lib "kernel32" Alias
> > "OutputDebugStringA" _ (ByVal lpString as String)
> >                           
> >                           
> >                           
> > Public Sub DbgPrint(ByVal sTxt As String)
> >   Dim sStr As String
> >   
> >   sStr = "["  & App.ExeName & "] " & sTxt & vbCrLf & Chr(0)
> >   Call OutputDebugString(sStr)
> > End Sub
> > '
> > ====================================================================

> Arne,
> Not sure I follow; - I already implement a central error handling
> system that writes to error.log so what useful purpose would a
> runtime messaging system serve? (I haven't read the link yet!)

Central error handler and logging is fine, but the above allows you to
have something similar to "Debug.Print" even inside the compiled
program, at that point, firing the debugview tool you'll be able to see
the debug messages you inserted into the code, it's useful to diagnose
issues which only surface in the compiled program and not in the IDE or
to trace/time the code to improve/optimize it; a better module is the
class below, the code and usage should be pretty straightforward, you
declare the class as a global in your project and instance it, then,
set the desired logging types (or no logging) whose value may (e.g.) be
stored and retrieved from your application config data, at that point,
wherever you'll need to send a "debug/trace" message you invoke the
DbgPrint() method of the class passing it the message and the message
type, the method will internally check if logging is enabled and if
that message type is enabled and, if so, will send the message to the
debugger console (if running, if not the API call returns immediately)



'
' CDbgLog.cls - class to send debug/trace messages to a debug console
'               like the "debugview" from SysInternals
'
' the class allows to specify a bitmask to enable/disable selected
' message types, for example one may set the LogLevel property like
'
' gCDbg.LogLevel = mtError + mtWarning + mtDebug
'
' the above will only enable error, warning and debug message and will
' ignore (drop w/o sending to the debugger) all the others
'

Option Explicit

' message types
Public Enum enMsgType
  mtNone = 0
  mtError = 1
  mtWarning = 2
  mtInformation = 4
  mtVerbose = 8
  mtDebug = 16
End Enum

' Debugger API
Private Declare Sub OutputDebugString Lib "kernel32" _
                          Alias "OutputDebugStringA" _
                          (ByVal lpString as String)


' private workareas
Private mbIsIDE    As Boolean
Private mnLogFlags As enMsgType

' initializes the class module
Private Sub Class_Initialize()
  On Local Error Resume Next
  mnLogFlags = mtError
  mbIsIDE = False
  Err.Clear
  Debug.Print 1/0
  If Err.Number <> 0 Then
    mbIsIDE = True
  End If
  Err.Clear
End Sub

' set the logging flags
Public Property Let LogFlags(ByVal nFlags As enMsgType)
  mnLogFlags = nFlags
End Property

' reat the logging flags
Public Property Get LogFlags() As enMsgType
  LogFlags = mnLogFlags
End Property

' sends a message to the debugger
Public Sub DbgPrint(ByVal sStr As String, _
                    Optional ByVal nType As enMsgType = mtInformation)
  Dim sType As String, sMsg As String
                    
  ' check if logging/message type is enabled
  If (mnLogFlags = mtNone) Or ((mnLogFlags And nType) = 0) Then
    Exit Sub
  End If

  ' initialize message
  sMsg = MsgType(nType) & " " & sStr

  ' if in IDE, send to immediate
  If mbIsIDE Then
    Debug.Print sMsg
  End If

  ' compose the debugger message
  sMsg = "[" & App.ExeName "]" & sMsg & vbCrlf & Chr(0)
         
  ' send to debugger (if any)
  Call OutputDebugString(sMsg)
End Sub

' decode a message type to string
Private Function MsgType(ByVal nType As enMsgType) As String
  Dim sType As String

  Select Case nType
    Case mtError
      sType = "ERROR      "
    Case mtWarning
      sType = "WARNING    "
    Case mtInformation
      sType = "INFORMATION"
    Case mtVerbose
      sType = "VERBOSE    "
    Case mtDebug
      sType = "DEBUG      "
    Case Else
      sType = "UNKNOWN    "
  End Select
  MsgType = "[" & sType & "]"
End Function









Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-02 11:11 -0500
  Re: MS Excel COMAddins Manager VB6 app Arne Saknussemm <idm.10.arnsak@mamber.net> - 2019-12-04 09:46 +0100
    Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-04 12:59 -0500
      Re: MS Excel COMAddins Manager VB6 app Arne Saknussemm <idm.10.arnsak@mamber.net> - 2019-12-05 09:44 +0100
        Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-05 03:57 -0500
          Re: MS Excel COMAddins Manager VB6 app Arne Saknussemm <idm.10.arnsak@mamber.net> - 2019-12-05 10:11 +0100
            Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-05 04:39 -0500
    Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-05 07:27 -0500
      Re: MS Excel COMAddins Manager VB6 app Arne Saknussemm <idm.10.arnsak@mamber.net> - 2019-12-05 14:36 +0100
        Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-05 08:39 -0500
        Re: MS Excel COMAddins Manager VB6 app Arne Saknussemm <idm.10.arnsak@mamber.net> - 2019-12-05 14:46 +0100
          Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-05 15:58 -0500
            Re: MS Excel COMAddins Manager VB6 app Arne Saknussemm <idm.10.arnsak@mamber.net> - 2019-12-06 09:29 +0100
              Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-06 04:47 -0500
                Re: MS Excel COMAddins Manager VB6 app Arne Saknussemm <idm.10.arnsak@mamber.net> - 2019-12-06 13:16 +0100
                Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-06 12:52 -0500
                Re: MS Excel COMAddins Manager VB6 app Arne Saknussemm <idm.10.arnsak@mamber.net> - 2019-12-09 09:28 +0100
                Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-09 03:52 -0500
                Re: MS Excel COMAddins Manager VB6 app ObiWan <obiwan@mvps.org> - 2019-12-09 10:12 +0100
                Re: MS Excel COMAddins Manager VB6 app GS <gs@v.invalid> - 2019-12-09 09:42 -0500

csiph-web