Conditional include

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

Is there a way to conditionally include parts of code in a vb.net project? I
am creating an app for two clients with slightly different requirements. I
figure if I can set the condition at the top of the project, I can compile
the same app for either of the clients.

Thanks

Regards
 
Hi John,

You can use conditional compiler directives:

Here's an example from MSDN:

#Const CustomerNumber = 36
#If CustomerNumber = 35 Then
' Insert code to be compiled for customer # 35.
#ElseIf CustomerNumber = 36 Then
' Insert code to be compiled for customer # 36.
#Else
' Insert code to be compiled for all other customers.
#End If
 
John,
You can use the Conditional Compilation to include or exclude parts of your
code.

For details see:

http://msdn.microsoft.com/library/d...n7/html/vaconConditionalCompilationPortal.asp

There is also a ConditionalAttribute that you can apply to a function so
that is it only called during certain builds of your project.

<Conditional("DEBUG")> _
Public Sub Dump()

End Sub

You can call the Dump function unconditionally within your program, during
Debug builds the function will be called and executed, during release builds
the function will not be called. This is how the Debug.WriteLine function
performs its magic.

Hope this helps
Jay
 
Back
Top