By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Make code not execute for a Debug build

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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

"Tom" wrote:
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

Nov 20 '05 #2

P: n/a
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" <an*******@discussions.microsoft.com> wrote in message
news:2c*****************************@phx.gbl...
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

Nov 20 '05 #3

P: n/a
* "Tom" <an*******@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4

P: n/a
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

"Herfried K. Wagner [MVP]" wrote:
* "Tom" <an*******@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #5

P: n/a
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" <Br***@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
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

"Herfried K. Wagner [MVP]" wrote:
* "Tom" <an*******@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #6

P: n/a
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
news:uo**************@TK2MSFTNGP11.phx.gbl...
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" <Br***@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
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

"Herfried K. Wagner [MVP]" wrote:
* "Tom" <an*******@discussions.microsoft.com> scripsit:
> 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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 20 '05 #7

P: n/a
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 [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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 news:uo**************@TK2MSFTNGP11.phx.gbl...
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" <Br***@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
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

"Herfried K. Wagner [MVP]" wrote:

> * "Tom" <an*******@discussions.microsoft.com> scripsit:
> > 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.
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>
>



Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.