Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if in IDE 1

Status
Not open for further replies.

ADoozer

Programmer
Dec 15, 2002
3,487
0
0
AU
ok, im not sure how to phrase this question so bear with me...

back when i used to play with C++ there was a switch i could use (before void main(){}) to check what OS was in use and load a library based on that

ie:

#if win32
#else if win16

or something to that effect...

is there a similar kind of call that can be made in VB to check if the program is open in IDE or as an exe?!?!

i realise this isnt a well structured question, but i couldnt think of a better way to write it!!

any input appreciated!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
I do not care for this method but it is simple and serves the purpose.
Of course you could also check the parent, whether started from VB6.exe or the myApp.exe itself.


Function AreWeInTheIDE() As boolean
On error goto errHandler
AreWeInTheIDE = false
'The line should get removed from the Exe
Debug.Print 1/0

Exit Function

ErrHandler:
AreWeInTheIDE=True
On error goto 0
End Function
 
thanks CCLINT ill give it a go...

>you could also check the parent

i dont follow, is that done with API (or am i wearing my dunces hat again?)

thanks for the input

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
to ADoozer:

If you still experience difficulties there's API function IsDebuggerPresent which must help.However it's supported only starting with Win98.
 
ok, let me be more specific...

i want to check if im in the IDE, if i am i want to dim my object as a specific thing (ie, excel.application) and if its packaged i want to declare it as object!!

the sole purpose is 1) i get the intelisense in debug mode 2) its not dependant on a referance (ie excel object library 9.0) when packaged!

i think that makes more sense,

CCLINT's earlier suggestion, i have tried but i think im missing something (IDE keeps buggin out)

so in summation:

if ImInIDE then
dim myobject as specific.object
set myobject=new specific.object
else
dim myobject as object
set myobject=createobject("myobjectthatiwant")
end if

hope that makes sense?!?

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
cheers DrJJ, virtually the same as CCLINTS post(give or take a word or too), like i said i may be in dunce mode today cos im missing the point somehow and cant get it workin (it always says its an exe!!)

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
Well, theoretically you could check the App.Path and see if it's the path to your VB directory ( such as C:\Program Files\Microsoft Visual Studio\VB98 ) or whatever. If it is, then you know it's running out of the IDE. Otherwise it's your compiled program.

Usercontrols have the AmbientPropeties.UserMode property. Too bad the VB forms don't.

You also have App.hInstance. If it's running from the IDE then the hInstance value will be the same as the IDE, but you'd have to go through all of the processes to find out what the IDE instance value is!

Robert
 
And you can use the CreateToolhelp32Snapshot to see if your program is defined as a running EXE. Very similar to the approach suggested by TheVampire, searching for your EXE name in the process list. If you cannot find your EXE in the list, then you're running from the IDE.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
hmmm... i was hoping this would be a simple task, however it looks like im gonna have to go back to just changing it in the IDE when i compile!!!

o well thanks all for the input!!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
ADOOZER:
The Function works for me if I drop it on a form as
a Private Fuction or Drop the Keyword Private and
put it in a module with my other Global/Public
Declarations
Code:
Private Function InIDE() As Boolean  'Form Declare
   On Error GoTo ImInIDE
    
    Debug.Print 1 / 0
    InIDE = False
    Exit Function
ImInIDE:
    InIDE = True
End Function
Function InIDE() As Boolean  'Module Declare
   On Error GoTo ImInIDE
    
    Debug.Print 1 / 0
    InIDE = False
    Exit Function
ImInIDE:
    InIDE = True
End Function
Then I put this in Form Load
Code:
If InIDE Then
   MsgBox "I'm in the Ide"
Else
   MsgBox "I'm in the Exe"
End If
I Ide gets IDE MsgBox; exe gets EXE MsgBox


jayare
 
Here's a very simple one: use a command line argument.

Access the Project Properties for your VB project. On the Make tab, enter "RunningFromIDE" in the Command Line Arguments TextBox. This command line argument will be removed when you compile your program to an executable but it will be present when you're running in the IDE. To test for it, add something like this to your project code:

Private Function RunningFromIDE() As Boolean
RunningFromIDE = False
If InStr(Command(), "RunningFromIDE") Then
RunningFromIDE = True
End If
End Function

Private Sub Form_Load()
If RunningFromIDE Then
MsgBox "Running from Inside the Visual Basic IDE"
End If
'...
End Sub

Simple but effective...

Merlijn is the name, and logic is my game!
 
thanks all... just realised why it wasnt working (i think)

i was trying to do the following:-

#if AreWeInTheIDE then
dim lalala as ladeda
#else
dim lalala as deedledum
#end if

Function AreWeInTheIDE() As boolean
On error goto errHandler
AreWeInTheIDE = false
'The line should get removed from the Exe
Debug.Print 1/0

Exit Function

ErrHandler:
AreWeInTheIDE=True
On error goto 0
End Function

which doesnt actually call the function (i dont think) (what can i say, i was in numbnuts mode yesterday)

however i realised i had some code by johnyingling (sitting in my faq)

#Constant blnEarly = True ' Use Intellisense
#If blnEarly Then
Dim excApp As Excel.Application
#Else
Dim excApp As Object
#End If

so all i need to do is change blnEarly to false and then compile, and this seems to work!!

thanks all for the input, and apologies for my lack of grey matter!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
Thanks, Merlijn. This was just what I needed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top