Solved

How to detect debug mode vs. run mode?

Posted on 1998-09-23
10
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Technology Partners: 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!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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