Doing a #ifdef in Visual Basic??? 
Author Message
 Doing a #ifdef in Visual Basic???

Hi, forgive me if this has been asked before, but I've only just subscribed
to this.

I need to know how to access the "custom constants" that are specified in
the build parameters in the project properties. This is so that I can
specify different code to be run/compiled, depending on what project
configuration I set - kinda similar to doing a "#ifdef" in a C or C++
program. The difference seems to be that custom defines specified in a C++
program's project properties actually make it into the code, where as Visual
Basic.Net doesn't seem to know anything about them apart from by going and
asking VisualStudio itself (surely it can't be that daft?).

To explain it a little more clearly, I'm coding a web content managing
program which needs to have two versions. One for the web developer, and one
for their clients. Hence I've got two different builds configurations, well,
four if you count debug & release versions, i.e.

Developer_Debug
Developer_Release
Client_Debug
Client_Release

I then have specified a constant in the build options to tell the code which
configuration I am using so I can hide certain GUI items from the Clients,
i.e.

Developer_Debug      ISDEVELOPER=true
Developer_Release    ISDEVELOPER=true
Client_Debug         ISDEVELOPER=false
Client_Release       ISDEVELOPER=false

But I can't seem to manage to get hold of the ISDEVELOPER constant
independent of the VisualStudio.NET DTE classes (my experience has been that
you can't get a handle to the DTE when running outside of VisualStudio in a
distributed application - it actually needs Visual Studio there to find it)

So does anyone have a clue how I can do this?

Regards

Andy



Sat, 29 Oct 2005 17:33:49 GMT  
 Doing a #ifdef in Visual Basic???
Andy,

#If ISDEVELOPER Then
 .. do this ..
#Else
  .. do that ..
#End If

Mattias

===

http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.



Sat, 29 Oct 2005 20:49:42 GMT  
 Doing a #ifdef in Visual Basic???
Doh! Thanks Mattias. Knew it'd be something simple As your next challenge,
try finding that in the documentation assuming that you didn't know about
the "#if" statement. ;-D

Many thanks

Andy


Quote:
> Andy,

> #If ISDEVELOPER Then
>  .. do this ..
> #Else
>   .. do that ..
> #End If

> Mattias

> ===

> http://www.msjogren.net/dotnet/
> Please reply only to the newsgroup.



Sat, 29 Oct 2005 22:02:57 GMT  
 Doing a #ifdef in Visual Basic???
Andy,
Not that its any more obvious (than searching for #if). :-)

Look up 'Conditional compilation' in the on-line help.

Hope this helps
Jay


Quote:
> Doh! Thanks Mattias. Knew it'd be something simple As your next challenge,
> try finding that in the documentation assuming that you didn't know about
> the "#if" statement. ;-D

> Many thanks

> Andy



> > Andy,

> > #If ISDEVELOPER Then
> >  .. do this ..
> > #Else
> >   .. do that ..
> > #End If

> > Mattias

> > ===

> > http://www.msjogren.net/dotnet/
> > Please reply only to the newsgroup.



Sat, 29 Oct 2005 23:49:45 GMT  
 Doing a #ifdef in Visual Basic???

Quote:

> Hence I've got two different builds configurations, well,
> four if you count debug & release versions, i.e.

> Developer_Debug
> Developer_Release
> Client_Debug
> Client_Release

According to the VB.NET docs regarding #If Then #Else (which you've probably
read now :-) ) you can use the Config compiler constant, but unless there's a
better constant expression than

#If Config > "Developer" Then ' matches both Developer configurations.

using an IsDeveloper constant is probably preferable.

Of course you could define

#Const IsDeveloper = (Config > "Developer")

to make further tests readable.

BTW The (1.1) docs state "Regardless of the outcome of any evaluation, all
expressions are evaluated using Option Compare Text. " but I've seen the
opposite to be true. That is "A" < "AB" < "Ab" < "a" < "ab".

For command line SDK users:

I found this NT (2000) command line successfully defines a string constant:

vbc -d:"ConstValue=\"SomeString\"" condcomp.vb

Also, Debug is not automatically defined by using the -debug+ command line
argument; -d:debug=-1 or the more readable -d:debug=True is required.

Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)



Sun, 30 Oct 2005 02:43:13 GMT  
 Doing a #ifdef in Visual Basic???
Hello,


Quote:
> Doh! Thanks Mattias. Knew it'd be something simple As
> your next challenge, try finding that in the documentation
> assuming that you didn't know about
> the "#if" statement. ;-D

"Conditional Compilation Overview":

http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconUnderstanding...

Regards,
Herfried K. Wagner



Sun, 30 Oct 2005 06:05:40 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. This can be done by using the Visual Basic Shell command

2. Can video capture be done with visual basic?

3. Book: Doing objects in Visual Basic

4. Doing Cool Tricks w/ Visual Basic...

5. Doing Cool Tricks w/ Visual Basic...

6. do Visual Basic 6.0 and Visual Basic .NET version beta Working Both

7. Difference between Visual Basic 6 and Visual Basic.Net

8. Visual basic 4 to Visual basic 6

9. Visual Basic 3.0 to Visual Basic 6.0

10. Visual Basic 5 vs. Visual Basic 6

11. Visual basic programs - connect to a server - Visual Basic 5 Enterprice Edition

12. loading visual basic 3.0 applications in visual basic 5.0

 

 
Powered by phpBB® Forum Software