|
-
Jul 7th, 2004, 10:05 PM
#1
Thread Starter
Frenzied Member
How to know if code has been Compiled? (Solved)
Alright... I have seen this in a couple of sites as a tip which tells you if you are on the VB IDE or you are running the EXE the IDE made.
Here is the code for that:
VB Code:
#Const DebugVer = True
#If DebugVer Then
MsgBox "This is the Debug Version Please Report any Messages"
#Else
MsgBox "This is the Final Version :)"
#End If
Now... Why doesn't this code work for me?
I tried running it on a Form and I would always get "This is the Debug Version..." (I mean, after compiling and running the file.exe, of course), then I tried it on a Module and still the same result...
What am I doing wrong?
Here are the two locations where I found this "tip":
First Source Second Source
Last edited by Tec-Nico; Oct 3rd, 2004 at 01:56 PM.
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Jul 7th, 2004, 10:18 PM
#2
Try this instead.
VB Code:
Option Explicit
' Flag for debug mode
Private mbDebugMode As Boolean
' Set mbDebugMode to true. This happens only
' if the Debug.Assert call happens. It only
' happens in the IDE.
Private Function InDebugMode() As Boolean
mbDebugMode = True
InDebugMode = True
End Function
' Set the mbDebugMode flag.
Private Function InIDE()
' This will only be done if in the IDE
Debug.Assert InDebugMode
If mbDebugMode Then
InIDE = True
End If
End Function
Private Sub Form_Load()
' See if we are running in the IDE.
If InIDE Then
MsgBox "In the development environment"
Else
MsgBox "In a compiled executable"
End If
End Sub
-
Jul 7th, 2004, 10:34 PM
#3
Here's a really simple way that I found by searching the CodeBank.
Option Explicit
VB Code:
Private Function InIDE() As Boolean
On Error Resume Next
Debug.Print 1 / 0
InIDE = (Err.Number <> 0)
End Function
Private Sub Form_Load()
If InIDE Then
MsgBox "I'm in IDE"
Else
MsgBox "I'm compiled"
End If
End Sub
-
Jul 7th, 2004, 10:47 PM
#4
Thread Starter
Frenzied Member
Wow! Thank you very much Martin!!!
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Jul 8th, 2004, 04:57 AM
#5
Re: How to know if code has been Compiled?
Originally posted by Tec-Nico
VB Code:
#Const DebugVer = True
#If DebugVer Then
MsgBox "This is the Debug Version Please Report any Messages"
#Else
MsgBox "This is the Final Version :)"
#End If
MartinLiss has given you code for checking to see if the app is being run from the IDE or from the EXE. This is the code most developers use.
However, going back to your original code above, you have this slightly wrong.
If you have:
VB Code:
Private Sub Form_Load()
#If DebugVer Then
MsgBox "This is the Debug Version Please Report any Messages"
#Else
MsgBox "This is the Final Version :)"
#End If
End Sub
Then what you do is go to Project/Properties...Then go to the "Make" tab and in the "Conditional Compilation Arguemnts" text box add:
-1 = True
0 = False
And now run your app.
If you have DebugVer = 0 then when you compile you app the code:
VB Code:
MsgBox "This is the Debug Version Please Report any Messages"
WILL NOT BE included in the EXE code. It's completely missed out.
Woof
-
Jul 8th, 2004, 05:56 AM
#6
Hyperactive Member
Whats the use of this code ? Why do you want to know where you are ? I don't understand!
Tapan Bhanot,
CEO, Avis Software.
Website: www.avissoftware.com
-
Jul 8th, 2004, 06:01 AM
#7
Originally posted by AvisSoft
Whats the use of this code ? Why do you want to know where you are ? I don't understand!
One possible use would be to skip over subclassing while in the IDE. Since a run-time error when subclassing would cause the IDE to crash, it can be a good idea to not subclass when trying to debug something else.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 8th, 2004, 06:06 AM
#8
On example for the conditions compilation arguments is for say a demo version of your software:
So you add:
To the compilation arguments. Then in your code you do:
VB Code:
Public Sub AddRecordToDB()
#If DEMO Then
'add code to count number of records
'if record count > 20 then
Err.Raise vbObjectError, , "Demo version. Max 20 records allowed"
#End If
'Code to add record
End Sub
So when you compile the DLL, or EXE it's compiled as a demo version or a full version.
Another example for working out if it's IDE or EXE is you may want to use different file paths etc.
Woka
-
Jun 25th, 2005, 07:44 AM
#9
Fanatic Member
Re: How to know if code has been Compiled? (Solved)
In similar theme, this is a bit of code we use to make sure an app will NOT compile.
VB Code:
Option Explicit
#Const TEST = True
Sub BadFunction()
#If TEST Then
[COLOR=Red]Will not compile if TEST is true[/COLOR]
#End If
End Sub
Sub ExampleFunction()
#If TEST Then
'generate fake data for testing
#Else
'get real data from the satellite
#End If
End Sub
Why?
We set TEST true to test applications in the IDE.
For instance we may generate fake data instead of getting data from instrumentation that is not connected.
Obviously it would be a disaster if somebody forgot to set TEST to false, compiled the app and it and sent it to a customer. This way they CAN'T compile it if they forget.
Brian
(Fighting with the RightToLeft bugs in VS 2005)
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
|