Click to See Complete Forum and Search --> : Run from devellopement environment


Gek
August 7th, 2001, 05:28 AM
hi there

Is there a way to check if the program i'm writing runs from the devellopement environment or as exe? this would be great for debugging.

thanks, daniel

Cakkie
August 7th, 2001, 06:14 AM
There are various ways to check so. You could use the name of the executable executing the program. In the IDE, it should be VB5 or VB6.exe, in runtime, this should be the name of your program.
Another way, much easier, is the following.

public Function IsInDebug() as Boolean

on error goto ErrHandler
debug.print 1 / 0
IsInDebug = false
Exit Function

ErrHandler:
IsInDebug = true

End Function

'somewhere else
If IsDebugging then
Msgbox "Running in IDE"
else
Msgbox "Running compiled"
End If



What it does is it does a division by zero, so an error is raised and the function returns true. However, when compiled, all refferences to Debug are ignored, so the statement isn't executed, no error is raised, and the function returns false.

Source: www.vbcodelibrary.co.uk

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Cimperiali
August 7th, 2001, 06:35 AM
In a module bas, write a sub main() and make it the starting point of your app
option Explicit
private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (byval lpModuleName as string) as Long
public RunningInIde as Boolean

Sub Main()
Dim RunningInIde as Boolean
If App.StartMode = vbSModeAutomation then '=1=Activex component
Exit Sub
ElseIf App.StartMode = vbSModeStandalone then '=0= as standalone or within IDE
#If Win32 then
If GetModuleHandle("VB32.EXE") Or GetModuleHandle("VB6.EXE") then
RunningInIde = true
End If
#else
If GetModuleHandle("VB.EXE") then RunningInIde = true
#End If
If RunningInIde then
'your code for running from VB ambient
else
'your code for running as standalone
End If
End If
End Sub




Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

Gek
August 8th, 2001, 01:49 AM
wow, cool idea! thanks!

daniel