Solved

Running inside VB5 or in EXE?

Posted on 1998-06-25
7
289 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Write data from SQL to CSV file - position 1 59
VBA filters 2 59
Access 2013 combo box not working 3 43
Automatic Email Reminder 4 36
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

806 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