Mike wrote, quoting Herfried Wagner:
[Mike]
Also, now that VB.NET supports the INTERFACE declaration, the
creativity is expanded for VB.NET people:
Public Interface IDemo
funtion CheckLicense() as boolean
sub CrippleCode(byval OnOff as Boolean)
End Interface
#if DEMO_VERSION then
#include "implement_idemo_trial_version.vb"
#else
#include "implement_idemo_full_version.vb"
#end if
{Herfried]
#Const LICENSE_VERSION_TRIAL = 1
#Const LICENSE_VERSION_FULL = 2
#Const LICENSE_VERSION = LICENSE_VERSION_TRIAL
///
\\\
Friend Interface ILicenseValidator
Function ValidateLicense() As Boolean
End Interface
///
"TrialLicenseValidator.vb":
\\\
#If LICENSE_VERSION = LICENSE_VERSION_TRIAL Then
Friend Class TrialLicenseValidator
Implements ILicenseValidator
Friend Function ValidateLicense() As Boolean _
Implements ILicenseValidator.ValidateLicense
...
End Function
End Class
#End If
///
\\\
#If LICENSE_VERSION = LICENSE_VERSION_FULL Then
Friend Class FullLicenseValidator
Implements ILicenseValidator
Friend Function ValidateLicense() As Boolean _
Implements ILicenseValidator.ValidateLicense
...
End Function
End Class
Hmmmmmmm, 9 lines of code versions 51 lines... hmmmmmmmm
I get your point. See ya.
<snip>
Lol, it seems you are having a little trouble to *aham* open your mind
to the fact that this use of #include is not really necessary in the
way compilation happens in VB... In other words, it's not a case of a
bunch of completely illiterate newbie programmers that can't see the
value of proven compilation tricks of yore. It actually seems to be
the case of a *new* guy in town who can't get rid of his past habits
and embrace the way of the language he's trying to learn. I know how
you must be feeling, one of the first things I did when I started
programming in C++ was to hack Properties into the language -- you
know, instead of those uggly C->GetValue()/C->SetValue(V) things.
Yeah, stupid from a C++ programmer point of view, even though
perfectly plausible from the point of view of a VB programmer new to
the C++ way of life, who wondered how no C++ programmer could see the
obvious value of having getters/setters with the same name and a
distinctive syntax =D.
I guess you'll have to live with the fact that programming units in
VB.Net are more "closed" than, say, in C/C++ and the use of the pre-
processor (which, if I'm not mistaken, dates back from VB 3.0) is very
limited (fortunately, IMHO) if compared to the (in)famous pre-
processing approach in those languages (I may be wrong, but it seems
Stroustrup himself abhors the C preprocessor [1], not only because of
the #include directive, but also because of the #define directive that
you also seem to like -- and I sense your next argument will be that
Vb.Net is crippled because we don't have such a powerfull macro
mechanism =)). At least, that's the way the compiler works in the IDE.
If you use another editor and call the command-line compiler yourself
(using custom build files) I don't see why you couldn't hack this kind
of preprocessing. But if you use the IDE, this kind of functionality
ins't provided and you can get by without it by using other
approaches, such as the one Herfried exemplified (btw, leaving in his
example only the lines responsible for the "inclusion" of the correct
code, his solution accounts for 4 lines of code, only, not 51 as you
stated =)))))
Best regards and good luck with your VB.Net experiments.
Branco.
[1]
http://www.research.att.com/~bs/bs_faq2.html#macro