Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use #IF DEBUG in VB.NET

Tags:

.net

vb.net

Is it possible to assign a value to a class variable from inside a #IF DEBUG conditional?

I want to conditionally execute some code from inside my main form load if I am running in DEBUG mode. I thought I could do something like:

Public Class Form1     public DEB as Integer      #if DEBUG then         DEB = 1     #else         DEB = 0     #end if      Private Sub Form1_Load(....)         if DEB=1 Then             <do something>         else             <do something else>         end if     .... 

However, it seems like you can't assign a value to a variable. I'm obviously not understanding the scoping correctly. I can't seem to put the #if DEBUG inside the Load sub routine. How do I do this?

like image 806
GregH Avatar asked Aug 31 '10 21:08

GregH


People also ask

How do we use a semicolon?

Use a semicolon to replace a period between related sentences when the second sentence starts with either a conjunctive adverb or a transitional expression, such as for example, for instance, that is, besides, accordingly, furthermore, otherwise, however, thus, therefore.

When should a semicolon be used examples?

A semicolon may be used between independent clauses joined by a connector, such as and, but, or, nor, etc., when one or more commas appear in the first clause. Example: When I finish here, and I will soon, I'll be glad to help you; and that is a promise I will keep.

How do you use commas and semicolons?

When a comma separates two complete sentences joined by a conjunction (and, but, or, nor, for, so, or yet) the comma and the conjunction can be replaced with a semicolon. I ate dinner, and I went to the movies. = I ate dinner; I went to the movies.

How do you use dashes correctly?

Use dashes to mark the beginning and end of a series, which might otherwise get confused, with the rest of the sentence: Example: The three female characters—the wife, the nun, and the jockey—are the incarnation of excellence. Dashes are also used to mark the interruption of a sentence in dialogue: Example: “Help!


1 Answers

Why not just test the compilation constant directly? You are not gaining anything by testing an actual variable.

Public Class Form1  Private Sub Form1_Load(....)  #if DEBUG then     <do something> #else      <do something else> #end if  End Sub  End Class 
like image 154
Christian Hayter Avatar answered Sep 30 '22 18:09

Christian Hayter