Solved

How to detect debug mode vs. run mode?

Posted on 1998-09-23
10
365 Views
Last Modified: 2008-02-01
I want to be able to log errors to a logfile if the exe version of my code is running but pop a message box up if the debug version is running (in the VB IDE).  How can I detect the difference?
0
Comment
Question by:debbyt
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:fguerreiro_inix
ID: 1436236
In your error handler put this:

errornumber = err.number            'save err number
err=0
on error resume next
debug.print errors(errornumber)
if err<>0 then                             'you are in exe mode
     logtofile
else                                            'you are in development mode
     msgbox errors(errornumber)
endif

This only works because using debug object in an exe causes
an error


Hope this helps
0
 

Author Comment

by:debbyt
ID: 1436237
Is there a property in VB that tells you whether or not the application is in debug mode (IDE) or run mode (exe)?  
0
 
LVL 1

Expert Comment

by:DennisH
ID: 1436238
The easiest way to do this debbie is to use a conditional compile flag in the Declarations section of the module being tested.

#Const Debugging = True

Then in your error handler use code like this:
#If Debugging then
    LogToFile
#Else
    MsgBox
#EndIf
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:debbyt
ID: 1436239
Does this make the detection of run mode vs. debug mode automatic?  Maybe I'm not understanding what you're saying but when I tried your suggestion I am always getting Debugging to be true regardless of whether I'm in run mode or debug mode.

Please Clarify.  Thanks.
0
 
LVL 2

Expert Comment

by:BergJC
ID: 1436240
I think with DennisH's answer you'll have to set that #Const Debugging = True when you are in the IDE, and then change it to #Const Debugging = False when you compile your .EXE
0
 
LVL 2

Expert Comment

by:BergJC
ID: 1436241
I think with DennisH's answer you'll have to set that #Const Debugging = True when you are in the IDE, and then change it to #Const Debugging = False when you compile your .EXE
0
 

Author Comment

by:debbyt
ID: 1436242
That makes sense.  However, does this mean there  is no  way to check for run vs. debug modes in code without having to manually change a parameter?  That's really what I'm looking for.
0
 
LVL 1

Expert Comment

by:DennisH
ID: 1436243
I don't know of any way.
0
 

Accepted Solution

by:
hackerpii earned 50 total points
ID: 1436244
Option Explicit
'     ' ************************************************
'     ' Win16-specific declarations and code
'     ' ************************************************

       #If Win16 Then
              '      '
              '      ' Win16 API calls used to get executing filename
              '      '
               Private Declare Function GetModuleFileName Lib "Kernel" _
               (ByVal hModule As Integer, ByVal lpFilename As String, _
               ByVal nSize As Integer) As Integer
               Private Declare Function GetWindowWord Lib "User" _
               (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
              '      '
              '      ' Window field offsets for GetWindowWord()
              '      '
               Private Const GWW_HINSTANCE = -6
               Function vbCompiled(hWndMain As Integer) As Boolean
               Dim hInst As Integer
               Dim nRtn As Integer
               Dim Buffer As String
              '      '
              '      ' Get instance associated with main form
              '      '
               hInst = GetWindowWord(hWndMain, GWW_HINSTANCE)
              '      '
              '      ' Create buffer for filename and retrieve
              '      '
               Buffer = Space$(128)
               nRtn = GetModuleFileName(hInst, Buffer, Len(Buffer))
               Buffer = Left(Buffer, nRtn)
              '      '
              '      ' Compare module filename with known VB environment name
              '      '
               If Right(Buffer, 7) = "\VB.EXE" Then
               vbCompiled = False
               Else
               vbCompiled = True
               End If
               End Function
       #End If

'     ' ************************************************
'     ' Win32-specific declarations and code
'     ' ************************************************

       #If Win32 Then
              '      '
              '      ' Win32 API call used to get executing filename
              '      '
               Private Declare Function GetModuleFileNameA Lib "kernel32" _
               (ByVal hModule As Long, ByVal lpFilename As String, _
               ByVal nSize As Long) As Long
               Function vbCompiled(Optional hWndMain As Variant) As Boolean
               Dim nRtn As Long
               Dim Buffer As String
              '      '
              '      ' Create buffer for filename and retrieve
              '      '
               Buffer = Space$(256)
               nRtn = GetModuleFileNameA(0&, Buffer, Len(Buffer))
               Buffer = UCase(Left(Buffer, nRtn))
              '      '
              '      ' Compare module filename with known VB environment name
              '      '
               If Right(Buffer, 9) = "\VB32.EXE" Then
               vbCompiled = False
               Else
               vbCompiled = True
               End If
               End Function
       #End If

This should do it.

HackerPII
0
 

Author Comment

by:debbyt
ID: 1436245
Sounds like what I'm looking for.  Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question