?
Solved

Running inside VB5 or in EXE?

Posted on 1998-06-25
7
Medium Priority
?
324 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Accepted Solution

by:
yowkee earned 400 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 19 hours left to enroll

850 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