Solved

Conditional Compilation

Posted on 2004-08-24
4
255 Views
Last Modified: 2010-04-23
I was wondering if there was an equivalent way to do this C++ code in VB.

#if _DEBUG
      #define RunMethod(x) RunMethodA(x)
#else
      #define RunMethod(x) x
#endif

The main reason I wish to do this is I will be writing a testing suite and I will be writing these functions into if statements
eg. if TestCondition(3>4) then
So when I compile it in Debug it will call TestCondition, but when it is compiled to Release mode it change to "if 3>4 then". The other reason I really need it done like this instead of just returning straight away from inside the TestCondition function if compiled in release mode is that the file which will contain the function shall be removed from the source before the Release version is compiled

0
Comment
Question by:Mike737
  • 2
4 Comments
 
LVL 19

Expert Comment

by:drichards
ID: 11889423
0
 
LVL 1

Author Comment

by:Mike737
ID: 11889446
Still doesn't solve my issue.
I need the #define specifically.

If I was to do it just as a #if,#else everytime for every if statment I write the extra number of lines I would have to write would be rediculous! I would be looking at an extra 300 lines in my code if I had 100 if statements in it.

I don't really think that just #if's by themselves are an acceptable soloution.

0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 250 total points
ID: 11893566
no you cannot do the above as code macros are not supported ...

you can however use the Conditional attribute on your classes (they will completely compile out including calls to them if symbol not set) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsconditionalattributeclasstopic.asp includes examples. This should do exactly what you are looking for.
0
 
LVL 1

Author Comment

by:Mike737
ID: 11899659
Looks like you are on the right track with that one.
Been able to get a nice little testing interface up and working with that one.

Absolutely awesome answer dude!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now