(#) in front of code???

VBHuguenot

Member
Joined
Aug 8, 2007
Messages
12
Programming Experience
1-3
I have been developing asp.net apps for a long time. I am studyging now for a vb.net windows app position and while I have been reviewing code, I came across this in a wrox book and it didn't state why they all of a sudden started all lines of code with a number sign(#) i.e.....

VB.NET:
#If True Then 
   dim x as string
#Else
   dim x as integer
#End if

   x = 10

Why is "IF, Else, Then" start with a # sign? as suppose just writing the code without a # sign. It also has more examples such as...

VB.NET:
#Const UserType = "Clerk"
#If UserType = "Clerk" then
...........

What is the use of the # signs?
I know its something silly that I am missing. Thanks in advanced.
 
I believe that this is used for conditional code outside of methods. Meaning that within a class file you can conditionally dimension variables. What I have used this for before was in Visual Basic 6 applications to declare windows API calls based on the operating system that the application was running on. I may be a bit off but I have only seen this outside of methods.
 
AHHH... Thanks. I see. I think you are right because this just saves time in the book to give examples as to write out a method every time it gives an example. Thanks ss7thirty!
 
I also saw that if it is in a method its a way to comment out a chunk of code located in "IF, elseif, else, End if, const". like the following will not execute, it will skip over the IF statement....

VB.NET:
#If Debug_Level = 1 Then
            Debug.WriteLine("Entering IsPhoneNumberValid(" & phone_number & ")")
            Debug.Indent()
#End If
 
Back
Top