Make code not execute for a Debug build

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

How can I make code not execute for a debug build, but do
execute for a production build?
I have code which prompts for an account and password when
the program starts up. It is a pain to have to answer that
when I repeatly run the program during debugging, but it
is desired by my client. Presently I just comment it out
when I am debugging, but I was wondering if there was a
more automatic way? Some type of conditional compilation
depending on the type of build?

On another note, I'd like to say that since I started
programming VB 6 weeks ago I have found this forum
incredibly useful. I've learned not only from the answers
to my questions but from others questions as well. I'd
like to thank the several of you who answer most of the
questions. It is incredibly helpful. You must put a lot
of time into it and it is incredibly useful as the
Microsoft documentation is so poor. Just out of
curisosity, what motivates you to put so much time into
helping people on this forum and what does the "MVP"
several of you have after your names mean?

Thanks,
Tom
 
I have a similar situation with one of my applications. Username/Password. I hardcode these two values in the text properties of the text boxes when debugging. If you find a better way I would like to use it too.

B
 
Pre-Processor Directives

#If DEBUG Then

'Do something

#End If


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
* "Tom said:
How can I make code not execute for a debug build, but do
execute for a production build?

\\\
#If DEBUG THen
...
#Else
...
#End If
///

In the project properties, make sure the checkbox that defines the
'DEBUG' constant is checked.
 
Bruin,
Another equivalent way to do this is to use custom constants. Within the build configuration properties of a projects properties under the build sub menu you can also define custom constants and their values to be used in the same way. By using a custom constant instead of the built in debug flag I am able to change the behavior in either debug or release mode.

For Example in the custom constants field (Debug configuration) enter SkipAnnoyingTasks=True
you can then use the same login
#IF SkipAnnoyingTasks=false
'prompt for credentials
#end if
 
I had not used this. Interesting, however, Im not sure why this might be
favourable to simply using #If Debug, perhaps you can illuminate ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

Bruin said:
Bruin,
Another equivalent way to do this is to use custom constants. Within the
build configuration properties of a projects properties under the build sub
menu you can also define custom constants and their values to be used in the
same way. By using a custom constant instead of the built in debug flag I
am able to change the behavior in either debug or release mode.
 
OHM,
#If DemoVersion Then
' save not allowed
#Else
' save allowed in the purchased version
#End If

Where you build two versions of your assembly, the Demo & the Purchased
version (conceptionally 4 versions: Release Demo, Release Purchased, Debug
Demo, and Debug Purchased).

Also if it wasn't mentioned in this thread the ConditionalAttribute is
handy.

<Conditional("FullVersion")> _
Public Sub FileSave()
#If FullVersion
' code to save a file only used in Full Version
#End If
End Sub

Then you can simply call FileSave and the call will be conditionally
included in your assembly, this is how all the methods on Debug & Trace
work, they all have a <Conditional("DEBUG")> attribute on them.

The #If FullVersion will remove the method body if you so choose...

Hope this helps
Jay
 
Good point, had not thought of that !

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

Jay B. Harlow said:
OHM,
#If DemoVersion Then
' save not allowed
#Else
' save allowed in the purchased version
#End If

Where you build two versions of your assembly, the Demo & the Purchased
version (conceptionally 4 versions: Release Demo, Release Purchased, Debug
Demo, and Debug Purchased).

Also if it wasn't mentioned in this thread the ConditionalAttribute is
handy.

<Conditional("FullVersion")> _
Public Sub FileSave()
#If FullVersion
' code to save a file only used in Full Version
#End If
End Sub

Then you can simply call FileSave and the call will be conditionally
included in your assembly, this is how all the methods on Debug & Trace
work, they all have a <Conditional("DEBUG")> attribute on them.

The #If FullVersion will remove the method body if you so choose...

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
I had not used this. Interesting, however, Im not sure why this might be
favourable to simply using #If Debug, perhaps you can illuminate ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

the
build configuration properties of a projects properties under the build sub
menu you can also define custom constants and their values to be used in the
same way. By using a custom constant instead of the built in debug
flag
 
Back
Top