|
-
August 7th, 2001, 05:28 AM
#1
Run from devellopement environment
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
-
August 7th, 2001, 06:14 AM
#2
Re: Run from devellopement environment
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
[email protected]
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
-
August 7th, 2001, 06:35 AM
#3
Re: Run from devellopement environment
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
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
August 8th, 2001, 01:49 AM
#4
Re: Run from devellopement environment
wow, cool idea! thanks!
daniel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|