|
-
Feb 11th, 2007, 03:53 PM
#1
Thread Starter
Lively Member
[RESOLVED] Check If In IDE or Not [.NET 2005]
I did a search and found this thread...
http://www.vbforums.com/showthread.p...ghlight=envdte
I tried the examples there to figure out the mode of the application...
Running it from IDE it returns "Debug"...
Running it in exe form from bin or release folder It also returns "Debug".
To be honest I don't even know what exe to use anyways. So maybe thats why it's not working. From my application folder I see a billion exes and was confused as to which one to use? Anyways assuming that i ran the right Exe.. What should the mode of the debugger say? "Release"?
-
Feb 11th, 2007, 06:11 PM
#2
Re: Check If In IDE or Not [.NET 2005]
What exactly is it that you want to do and under what circumstances? There are only two executables that should be being run: the one from bin\Debug when you're debugging and the one from bin\Release when you release your product.
-
Feb 11th, 2007, 08:41 PM
#3
Thread Starter
Lively Member
Re: Check If In IDE or Not [.NET 2005]
Well I run certain code in the exe that I don't want to have run in the ide.. so I need to figure out if the IDE exists or not.
Right now i just exclude it in the ide and then add it when I build it.. but that can get annoying... so i need a way to figure out if the IDE exists or not.
in vb6 I used..
VB Code:
Private Function InIDE() As Boolean
On Error GoTo errhand
InIDE = False
Debug.Print 1 / 0
Exit Function
errhand:
InIDE = True
End Function
which I got from the forums..
So can something similar to that be done in .net 05?
-
Feb 11th, 2007, 09:00 PM
#4
Re: Check If In IDE or Not [.NET 2005]
Firstly, don't use that form of error handling in .NET apps. Learn how to use structured exception handling with the Try...Catch...Finally...End Try structure.
Secondly, what I think you actually mean is that you want to execute different code depending on whether this is a debug or release build. In that case you use conditional compilation. Your code doesn't have to check for anything because the compiler does the work and only compiles the appropriate code for the current configuration:
VB Code:
#If DEBUG Then
'Place code to execute while debugging here.
#Else
'Place code to execute in final here.
#End If
You can two complete alternatives or you can just add something extra for one configuration, e.g.
VB Code:
Try
'Do something that might throw an exception here.
Catch ex As Exception
#If DEBUG Then
MessageBox.Show(ex.ToString())
#End If
MessageBox.Show("An error occurred while doing something.")
End Try
-
Feb 11th, 2007, 09:01 PM
#5
Re: Check If In IDE or Not [.NET 2005]
Having said that, you can make calls to the methods of the Debug class with impunity because they'll just be essentially ignored in release code.
-
Feb 11th, 2007, 10:34 PM
#6
Thread Starter
Lively Member
Re: Check If In IDE or Not [.NET 2005]
Thats what I meant, glad you understood me.
for what I need to do this works fine.. unless you disagree? 
VB Code:
Private Function InIDE() As Boolean
#If DEBUG Then
Return True
#Else
Return False
#End If
End Function
Thank you very much sir.
-
Feb 11th, 2007, 11:13 PM
#7
Re: Check If In IDE or Not [.NET 2005]
No, that's not what I meant. You don't need to declare a function that tells you whether you're debugging or not. You're supposed to use conditional compilation wherever you need to do different things depending on the configuration. You don't do this:
VB Code:
Private Sub SomeMethod()
If InIDE Then
'Do one thing.
Else
'Do another.
End If
End Sub
Private Function InIDE() As Boolean
#If DEBUG Then
Return True
#Else
Return False
#End If
End Function
You do this:
VB Code:
Private Sub SomeMethod()
#If DEBUG Then
'Do one thing.
#Else
'Do another.
#End If
End Sub
-
Feb 12th, 2007, 12:41 AM
#8
Thread Starter
Lively Member
Re: Check If In IDE or Not [.NET 2005]
Except after the Debug Check I run code that needs to be run weather or not I'm in debug.
Code:
code to run in exe
code to skip in debug [but i need to run in exe]
code to run in exe
I suppose I didn't phrase that right to begin with... the way you put it wouldn't work since you said it'll be skipped when you run in exe form.
Code:
code to run in exe
If Not inIDE Then
code to skip in debug [but i need to run in exe]
End if
code to run in exe
I think I got that right?
-
Feb 12th, 2007, 12:43 AM
#9
Thread Starter
Lively Member
Re: Check If In IDE or Not [.NET 2005]
Yea, I just re-read my original post.. I didn't specify how I was using the data right
-
Feb 12th, 2007, 12:48 AM
#10
Thread Starter
Lively Member
Re: Check If In IDE or Not [.NET 2005]
I suppose...
VB Code:
#If Not DEBUG Then
'Code to skip in IDE but Run in Exe
#End If
Would be better..
-
Feb 12th, 2007, 09:30 AM
#11
Addicted Member
Re: Check If In IDE or Not [.NET 2005]
If you've got line of code, "LineOfCode1", that needs to run in both debug time and runtime (exe), and LineOfCode2 that only needs to be run in debug mode, you could just simply copy and paste LineOfCode1 to both sections.
VB Code:
Private Sub SomeMethod()
#If DEBUG Then
'Do one thing.
LineOfCode1
LineOfCode2
#Else
'Do another.
LineOfCode1
#End If
End Sub
The compiler will strip your code of anything between "#If DEBUG Then" and "#Else", including the conditional syntax so that all your program is left with is the stuff you want to run outside of debug mode.
-
Feb 12th, 2007, 05:06 PM
#12
Re: Check If In IDE or Not [.NET 2005]
There's no point writing LineOfCode1 twice.
VB Code:
Private Sub SomeMethod()
LineOfCode1
#If DEBUG Then
LineOfCode2
#End If
End Sub
is the most correct way to write that code.
Last edited by jmcilhinney; Feb 12th, 2007 at 09:27 PM.
-
Feb 12th, 2007, 08:50 PM
#13
Thread Starter
Lively Member
Re: Check If In IDE or Not [.NET 2005]
Thanks jmcilhinney for helping me figure that out..
Problem Resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|