What is it? how to use that? what are the advatages of using it ?Code:#If DEBUG Then
LogMessage("Did first thing")
#End If
Printable View
What is it? how to use that? what are the advatages of using it ?Code:#If DEBUG Then
LogMessage("Did first thing")
#End If
it's called a compiler directive... it's a way of telling the compiler, "Hey, only run this stuff if the DEBUG flag has been set." ... that way it only runs while in debug mode, but doesn't run in the compiled code.
-tg
Debug is used as a development tool to view the values of you variables
eg:
Dim sName as string
sName = "Sally"
Debug.Print sName Looking in the immediate window will show Sally
or Debug.Print App.Path will show the path you are working on
many, many uses
Very handy tool
hey csKanna
#if is the compiler directive means it directs compiler to do some conditional tasks
following is the simple example just create an standard empty project and place a command button and then paste following in code window
you will only get one messagebox because you have not DEBUGGING set
vb Code:
Private Sub Command1_Click() #If DEBUGGING Then MsgBox "hello this is show when DEBUGGING is set" #End If MsgBox "This will be shown always" End Sub
after checking once just go to properties of project and under make tab u will find last text box named conditional compilation arguments and paste there the following statement
and then run the project again and click on button then will see the actual differenceQuote:
DEBUGGING = 1
NOTE : Debug is predefined object as @isnoend07 said so it can't be used for conditional compilation
hope this description will help you :-)
I'm also curious. I know there are two predefined precompilation constants, i. e. Win16 and Win32. You can write code like
#If Win32 then
...
#End If
if you want that your code would compile only under Win32. I think these are the only predefined precompilation constants in VB6. However, according to MSDN http://msdn.microsoft.com/en-us/library/swfss70d.aspx, there should also be other predefined constants. Do you think VB6 implements them? I tried, but those constants don't get capitalized as you type them, unlike Win16 and Win32, so I would guess they're not implemented. What do you think?