By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,640 Members | 1,331 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,640 IT Pros & Developers. It's quick & easy.

#define in VB .net?

P: n/a
Hello -

I would like to find a way to use a pre-processor directive like the
#define in C++. It seems like the #const in VB can only be used within
other # statements but not outside.

The problem is that I want to set a variable at the very top of the
*.vb file so users will see it and can adjust it if necessary. Then I
want to use the variable in a function call later in the code.

I tried adding a namespace with a const variable at the very top but it
will not work since I have Import statements later on.

Is there a way to do something similiar to what the #define directive
does?

Thanks!
Joe

Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
#Const TEST = True

I'm not sure what you mean when you say #Const can only be used within other
# statements however.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up outdated VB.NET code
"Joe HM" wrote:
Hello -

I would like to find a way to use a pre-processor directive like the
#define in C++. It seems like the #const in VB can only be used within
other # statements but not outside.

The problem is that I want to set a variable at the very top of the
*.vb file so users will see it and can adjust it if necessary. Then I
want to use the variable in a function call later in the code.

I tried adding a namespace with a const variable at the very top but it
will not work since I have Import statements later on.

Is there a way to do something similiar to what the #define directive
does?

Thanks!
Joe

Nov 21 '05 #2

P: n/a
"Joe HM" <un*******@yahoo.com> schrieb:
I would like to find a way to use a pre-processor directive like the
#define in C++. It seems like the #const in VB can only be used within
other # statements but not outside.

The problem is that I want to set a variable at the very top of the
*.vb file so users will see it and can adjust it if necessary. Then I
want to use the variable in a function call later in the code.


Mhm... I would use a property instead of the variable which can be set to a
certain value at /runtime/ rather than letting the user set the variable to
a certain value at compile-time.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
Ahhh - I see what you're trying to do now - you want to declare a constant
with #Const and access that constant from a non-pre-processor directive
statement.
Sorry - you can't do that.

But you can easily define constants at the top of your class:
Public Class TestClass
Private Const Test As Boolean = False

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up outdated VB.NET code
"Joe HM" wrote:
Hello -

I would like to find a way to use a pre-processor directive like the
#define in C++. It seems like the #const in VB can only be used within
other # statements but not outside.

The problem is that I want to set a variable at the very top of the
*.vb file so users will see it and can adjust it if necessary. Then I
want to use the variable in a function call later in the code.

I tried adding a namespace with a const variable at the very top but it
will not work since I have Import statements later on.

Is there a way to do something similiar to what the #define directive
does?

Thanks!
Joe

Nov 21 '05 #4

P: n/a
Hello -

I wanted the variable be a revision number that the user changes
whenever a change is made to the code. If this is located at the top
of the file with the revision history it would be less likely for the
user to forget to update this number.

How would I set a property?

Thanks,
Joe

Nov 21 '05 #5

P: n/a
Hello -

Yeah ... I would like to use the constant in a Console.WriteLine() or
similiar call. That's too bad that there is no such functionality. I
guess I will have to go with the definition at the top of the class.

Thanks,
Joe

Nov 21 '05 #6

P: n/a
"Joe HM" <un*******@yahoo.com> schrieb:
I wanted the variable be a revision number that the user changes
whenever a change is made to the code. If this is located at the top
of the file with the revision history it would be less likely for the
user to forget to update this number.


I don't really understand the purpose of the revision number. In .NET,
version numbers are specified on a per-assembly basis. You can change your
project's version number in the "AssemblyInfo.vb" file. More information on
versioning in .NET can be found here:

Structure of version numbers and methods to determine the version number
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=versioning&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7

P: n/a
Hello -

The revision number I need is totally unrelated to the revision number
of the project in the AssemblyInfo.vb file. The *.vb file is a script
for a test procedure and stand-alone without the *.vbproj or *.sln.

Thanks,
Joachim

Nov 21 '05 #8

P: n/a
Here's a work-around, if you prefer setting at the top of the file:

#Const Test = True

Public Class TestClass
Private TestValue As Boolean
Public New()
#If Test Then
TestValue = True
#Else
TestValue = False
#End If
End Sub
End Class
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up outdated VB.NET code
"Joe HM" wrote:
Hello -

I would like to find a way to use a pre-processor directive like the
#define in C++. It seems like the #const in VB can only be used within
other # statements but not outside.

The problem is that I want to set a variable at the very top of the
*.vb file so users will see it and can adjust it if necessary. Then I
want to use the variable in a function call later in the code.

I tried adding a namespace with a const variable at the very top but it
will not work since I have Import statements later on.

Is there a way to do something similiar to what the #define directive
does?

Thanks!
Joe

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.