determining if VB application is running in development mode 
Author Message
 determining if VB application is running in development mode

Hi, how can I tell if a VB application/DLL is currently only being run in
the development environment or stand-alone?

Richard



Sat, 09 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode
Richard

In VB go to your Project properties and click on the Make tab in the box
labeled "Command Line Arguments" type anything you like, for example put
"DEBUG" in there. Then in your code use something like this.

If Command = "DEBUG" then.....

Hope this helps!
Kurt


Quote:

> Hi, how can I tell if a VB application/DLL is currently only being run in
> the development environment or stand-alone?

> Richard



Sat, 09 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode
I do basically the same thing except.....
Instead of the word "DEBUG" which is easily passed as a command line argument to the compiled exe, I use "D|GN M?d?" with all of
those funky characters. It just makes it a little harder for someone to pass.

Another way is....
'==========
Option Explicit

Private Sub Form_Load()
   Show
   Print DesignMode
End Sub

Public Function DesignMode() As Boolean 'Place this function in a bas module or wherever.
   On Error Resume Next
   Debug.Print 1 / 0
   DesignMode = (Err.Number <> 0)
End Function
'==========

DesignMode will be True for the IDE and False for the EXE (since VB doesn't include Debug.Print in a compiled program)

Quote:

> Richard

> In VB go to your Project properties and click on the Make tab in the box
> labeled "Command Line Arguments" type anything you like, for example put
> "DEBUG" in there. Then in your code use something like this.

> If Command = "DEBUG" then.....

> Hope this helps!
> Kurt



> > Hi, how can I tell if a VB application/DLL is currently only being run in
> > the development environment or stand-alone?

> > Richard



Sat, 09 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode
This works in a VB6 standard exe:

    On Error Resume Next
    Debug.Print 1 \ 0
    If Err Then 'in IDE
        Err.Clear
        mnuTest.Visible = True
    Else 'not in IDE
        mnuTest.Visible = False
    End If

Quote:

>Hi, how can I tell if a VB application/DLL is currently only being run in
>the development environment or stand-alone?

>Richard



Sat, 09 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode
If you don't mind raising and trapping an error:

    On Error Resume Next
    Debug.Print 1/0
    bWeAreInTheIDE = (Err.Number <> 0)

Or a more complex function that avoids errors:

Public Function IsCompiled() As Boolean

    Static s_iState     As Integer
    Static s_bCompiled  As Boolean

    If s_iState = 0 Then
    ' first time we've called this function
        s_bCompiled = True
        s_iState = 1
        ' call IsCompiled() recursively, ONLY if run from the IDE...
        Debug.Assert Not IsCompiled()
        s_iState = 2
    ElseIf s_iState = 1 Then
    ' only get to here if called recursively, in which case we are NOT
compiled
        s_bCompiled = False
    End If

    IsCompiled = s_bCompiled

End Function

Both use the fact that methods of the Debug object are only executed in the
IDE, and not in a compiled EXE.

--
RobSmith


:
: Hi, how can I tell if a VB application/DLL is currently only being run in
: the development environment or stand-alone?
:
: Richard
:
:
:



Sat, 09 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode

Quote:

> Hi, how can I tell if a VB application/DLL is currently only being run in
> the development environment or stand-alone?

While the other ways will show you if you are in the IDE *FROM* the ide, the
following code can be used internally to the program to tell you if you are
running VB at the same time as your program.  It checks the task list for VB5 or
VB6.  This sort of code is most often used to check for registered versions of
code in a compiled run.  What most people want to do is check to to see if their
control is registered ONLY when not running in the IDE(ie only show the annoying
boxes if the person decides to compile and distribute the program).

here goes...(BTW this is 32 bit only code, ie vb5 and vb6)

Add it to a new module, and call it like so
if DevelopmentEnvironment(myForm.hWnd) then
        'working in IDE
else
        'running standalone
endif

===cut===
Option Explicit

Declare Function apiGetModuleFileName Lib "kernel32" Alias _
         "GetModuleFileNameA" (ByVal hModule As Long, ByVal _
         lpFileName As String, ByVal nSize As Long) As Long

Declare Function apiGetWindowWord Lib "user32" Alias _
         "GetWindowWord" (ByVal hwnd As Long, ByVal nIndex As _
         Long) As Integer

Global Const GWW_HINSTANCE = (-6)

Function DevelopmentEnvironment(my_hwnd As Long) As Boolean

    Dim ModuleName As String
    Dim FileName As String
    Dim hInst, ret As Integer

    ModuleName = String$(128, Chr$(0))
    ' Get the hInstance application:
    hInst = apiGetWindowWord(my_hwnd, GWW_HINSTANCE)
    ' Get the ModuleFileName:
    ' Enter the following two lines as one, single line:
    ModuleName = Left$(ModuleName, apiGetModuleFileName(hInst, ModuleName,
Len(ModuleName)))
    If (Len(ModuleName)) > 0 Then
        ' Get the "." in the file name. Then go back three characters.
        ' FileName should = \VB.EXE, so check for the backslash (\)
        ' because FileName could be GVB.EXE, which isn't the
        ' VB executable name:
        FileName = Mid$(ModuleName, InStr(ModuleName, ".") - 4)
        If FileName = "\VB6.EXE" Or FileName = "\VB5.EXE" Then
            DevelopmentEnvironment = True
        Else
            DevelopmentEnvironment = False
        End If
    End If

End Function

===cut===

--
 ----------------------------------------------------------------------------
| Jeff Goslin - MCSD,MCP | "Oh Bentson, you are so mercifully free from the  |

 ----------------------------------------------------------------------------
|   how come everyone elses religion is a cult but your cult is a religion   |
 ----------------------------------------------------------------------------
|      XGenetic, the ActiveX Artificial Intelligence Genetic Algorithm       |
|           http://www.winsite.com/info/pc/win95/demo/xgen-sw.zip/           |
 ----------------------------------------------------------------------------



Sat, 09 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode
Yet another way - it is never efficient to install error handlers to check
for things such as this, here's a short pure code method that I use....

Private Function TestVB(ByRef TestVar As Boolean) As Boolean
    TestVB = True
    TestVar = True
End Function

Public Function IsVBIDE() As Boolean
    Dim Test As Boolean        'Will be initialised to False
    Debug.Assert TestVB(Test)        'Since TestVB always returns True,
                                                      'Assert will not fail
    IsVBIDE = Test
End Function

The code works because VB only evaluates Assert statements when in the IDE.
Thus the Test variable will only be set to True if you are in the IDE. I
think you'll find this is the neatest way of achieving the desired result,
unless you do like using error traps. Also, this is not version dependent -
it will work in any version of VB after 5 (the Debug.Assert method was added
to the language in Version 5)

David Allsopp
Dave Software Enterprises

Quote:

> Hi, how can I tell if a VB application/DLL is currently only being run in
> the development environment or stand-alone?

> Richard



Sat, 09 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode
I'm using this:

Private Sub Command1_Click()

    Dim lpClassName As String * 255
    Dim strClassName As String

    'At runtime VB class names have the prefix "ThunderRT," for example:
ThunderCheckBox becomes ThunderRTCheckBox at runtime.
    GetClassName Me.hwnd, lpClassName, 256
    strClassName = Left(lpClassName, InStr(lpClassName, Chr(0)) - 1)
    'In run time, it will contain the string "RT":
    If InStr(1, strClassName, "ThunderRT", vbTextCompare) > 0 Then
        MsgBox "Run Time"
    Else
        MsgBox "Design Time"
    End If
End Sub


Quote:

> Hi, how can I tell if a VB application/DLL is currently only being run in
> the development environment or stand-alone?

> Richard



Sat, 09 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode

Thank you to all who took the time to reply, your suggestions were varied
and I will give each one a try to see which one works best for me, I think
Jeff Goslin was the closest to what I was looking for, I need to be able to
disable a DLL when running stand-alone, and only allow it to run in the IDE
for demonstration purposes

Thanks again to everyone ;o)

Richard

--
...

Quote:

> Hi, how can I tell if a VB application/DLL is currently only being run in
> the development environment or stand-alone?

> Richard



Sun, 10 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode


<cut>
Quote:
>         Debug.Assert Not IsCompiled()
<cut>
> Both use the fact that methods of the Debug object are only executed
in the
> IDE, and not in a compiled EXE.

<cut>

Just a minor clarification: not all methods of the Debug object are
totally discarded during compilation.  If you change your code above to
use "Debug.Print Not IsCompiled()" then the routine fails when
compiled.  This is because although the Debug.Print is ignored, any
function calls in the line are still done.  Apparently this is not true
for Debug.Assert since that does work.

--
Please reply via the newsgroup only

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 10 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode
Richard,

Check out Karl Peterson's "Ask the VB Pro" column from the June '99 VBPJ for
a way to do this. It has the advantages of Jeff's suggestion, but is simpler
and requires no passed parameters.

Best,

Peter Young


Quote:

> Hi, how can I tell if a VB application/DLL is currently only being run in
> the development environment or stand-alone?

> Richard



Sun, 10 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode


<SNIP>

Quote:
> it is never efficient to install error handlers to check
> for things such as this

Do you happen to have any benchmarks to prove this?  I'm not saying I
disagree with you, just wondering if this is really true.

- Jim

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 10 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode
Yes it is, but only at a very low level. You see, when you install an error
handler, jump instructions are added into the assembly language stream of
the VB compilers output. Because all of these examples are using 1/0 as an
error, they will require an interrupt hook for arithmetic error in the
processor. When the processor throws an exception and calls the appropriate
interrupt, it must first load the code for it which will be located in the
RAM and not in the processor cache. The processor must (slowly) load the
error handler from code. When you execute code in a "straight line" (vis my
example) the processor cache will handle execution so it will be quicker
because the RAM does not need to be read. In actual fact, in this example,
the error trap will be undetectably slower, it is simply better programming
technique to avoid jumping in programs. Everyone should know that GoTo is an
illegal word in Basic (!!) - so are error handlers that handle "avoidable"
errors. An error handler, in my opinion (and anyone is welcome to challenge
it) should only be used to trap unforeseeable errors such as hardware
failure (e.g. bad disk, disk not ready, permission denied etc..) and not
trappable errors such as divide by zero. It's only an opinion - both code
methods will work at virtually the same speed.

My apologies to assembly language purists out there who may note syntactical
errors in my explanation - I've only just started in assembly language!!

David Allsopp
Dave Software Enterprises

Quote:



> <SNIP>
> > it is never efficient to install error handlers to check
> > for things such as this

> Do you happen to have any benchmarks to prove this?  I'm not saying I
> disagree with you, just wondering if this is really true.

> - Jim

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Sun, 10 Nov 2002 03:00:00 GMT  
 determining if VB application is running in development mode
The reason for this lies in what Assertions actually are.

Debug.Print is designed for where you are actually evaluating something and
might want to see the results at debugging time.

Debug.Assert is Microsofts notion of an assertion language in VB. Assertion
languages (for example Eiffel) allow to specify Preconditions and
Postconditions as well as Invariant clauses on classes and routines. Such
assertions are only tests and so would not need to be evaluated at runtime.
The method used here takes advantage of this - really, the Not IsCompiled()
function should be evaluated at runtime because it's not a pure function,
but let's not get into a discussion of state machines!!!!!

David Allsopp


Quote:


> <cut>
> >         Debug.Assert Not IsCompiled()
> <cut>
> > Both use the fact that methods of the Debug object are only executed
> in the
> > IDE, and not in a compiled EXE.
> <cut>

> Just a minor clarification: not all methods of the Debug object are
> totally discarded during compilation.  If you change your code above to
> use "Debug.Print Not IsCompiled()" then the routine fails when
> compiled.  This is because although the Debug.Print is ignored, any
> function calls in the line are still done.  Apparently this is not true
> for Debug.Assert since that does work.

> --
> Please reply via the newsgroup only

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Fri, 20 Dec 2002 03:00:00 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. determining if VB application is running in development mode

2. Development mode or running.exe mode?

3. Determining VBIDE application mode from a VB add-in

4. Check in running in development mode

5. Runs compiled but in development mode...

6. How to determine if excel application is running on Internet Explorer using VB c

7. Determining if an application is running (VB 4.0 32)

8. Determining where a VB application is being run from

9. How to Determine the Number of VB Applications Running at Once

10. vb3.0 - Development mode or EXE(?) mode

11. DBGrid in Development Mode vs Deployment Mode

12. Determining Run mode

 

 
Powered by phpBB® Forum Software