Solved

Running inside VB5 or in EXE?

Posted on 1998-06-25
7
297 Views
Last Modified: 2010-05-03
I want to know if my program is running inside the VB5 development environment or in compiled EXE.
I can not use the App.EXEName because it will return the same name if the application name and the EXE name is the same.
Also, I succeeded to detect this in VB4 using API GetModuleFileName and GetWindowWord, but in VB5 they always report that the project is running in EXE. I think this is probably because VB5 compiles and runs the project as a true compiled application which is not the case in VB4 (I think).
I also tried to check the 'Compile to p-code' in the compile options, but got the same results.
Thanks.
0
Comment
Question by:gelco
7 Comments
 

Author Comment

by:gelco
ID: 1464344
Adjusted points to 200
0
 
LVL 2

Expert Comment

by:marti
ID: 1464345
One possible solution could be to set command line arguments to something specific while working in VB5 development environment.
0
 

Author Comment

by:gelco
ID: 1464346
Thanks marti, but I think this will not solve my problem.
I want some API code or some other way to do the real job.
Thanks again.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Accepted Solution

by:
yowkee earned 200 total points
ID: 1464347
gelco,

  Let's try this:

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

Function IsRunUnderVB5() As Boolean
 Dim S As String, Length
 Length = 256
 S = String(Length, 0)
 Call GetModuleFileName(0, S, Length)
 S = Left(S, InStr(S, Chr(0)) - 1)
 IsRunUnderVB5 = UCase(Right(S, 7)) = "VB5.EXE"
End Function
Private Sub Form_Load()
    If IsRunUnderVB5 Then
        MsgBox "Run Under VB5"
    Else
        MsgBox "Run in Exe"
    End If
End Sub
----------

Regards.
0
 

Expert Comment

by:LMSuporte
ID: 1464348
I am making this an answer: These function  doesnt require any API at all. It will return true if you are running in design time, false otherwise. To make sure this will work, go to the menu TOOLS, then OPTIONS, then choose the tab GENERAL and make sure your "Error Trapping" is set to "BREAK IN CLASS MODULE" (under VB5). In all other versions of VB, it will work just fine.
(PS: This might not work properly if you are creating an OCX and a VBP in the same project)

Public Function IsDesign() As Boolean

    On Error GoTo IsDesignIsTrue

    Debug.Print 1 / 0
    IsDesign = False
    Exit Function

IsDesignIsTrue:
    IsDesign = True

End Function

0
 
LVL 9

Expert Comment

by:Dalin
ID: 1464349
yowkee,
congradulations on your making the top 15. Keep up the good work.
regards
Dalin
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464350
Thanks, Dalin. It seem I start to be lazy after being the 15th :P...... Hope I could come back after good rest. My respect to you as you keep answering question here. It's not easy, really. :)

And gelco, are you there? Come and evaluate mine and LMSuporte's post.

 
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

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 …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

789 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