Conditional include

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

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
 
J

Jay B. Harlow [MVP - Outlook]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top