tags:

views:

67

answers:

5

Google is not good for searching for the # symbol

What effect does the # in front of the if make?

I am cleaning up someones mess and have never seen this before

+2  A: 

It is a Preprocessor Directive

e pre-processing directives provide the ability to conditionally skip sections of source files, to report error and warning conditions, and to delineate distinct regions of source code

SQLMenace
+2  A: 

Those are directives or "pre-processor directives". They basically allow for conditional compiling of VB code. Here is the VB-related MSDN article:

http://msdn.microsoft.com/en-us/library/tx6yas69.aspx

programatique
+2  A: 

On the surface, the behavior of the #If...Then...#Else directives appears the same as that of the If...Then...Else statements. However, the #If...Then...#Else directives evaluate what is compiled by the compiler, whereas the If...Then...Else statements evaluate conditions at run time.

http://msdn.microsoft.com/en-us/library/tx6yas69.aspx

Greg
A: 

The #If/#Else/#EndIf directives may be used to tell the compiler, Intellisense, etc. to ignore sections of code. If one encloses some code in an "If False Then ... End If" statement, the code will never execute, but the compiler will still process it, and Intellisense will still update it. If part of a program is surrounded by "#If False ... #EndIf", it will be essentially regarded as comments. There is no requirement that the stuff within a "#If False" directive be syntactically valid, and tools like "Rename variable" will not affect it.

supercat
+1  A: 

Just to give an examlpe (other has allready answered WHAT #-directive is):

#IF debug=true
 userhandler.login("stefan","mypassword")
#else
 userhandler.login(usernameTextbox.text,userpasswordTextbox.text)
#end if

When you run your code in debug mode the compiler will automatically handle the code in the true-part of the IF-condition. When you set the project to release and rebuild the project, it will use the other part of the if-condition. That way you can make the live as a programmer more easy for testing purposes and much other scenarios.

Stefan