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
Re: How to know if code has been Compiled?
Quote:
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
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.