473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

#define in VB .net?

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
8 29168
#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
"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
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
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Bryan Parkoff | last post by:
"#define" can only be inside the global scope before main() function. "#if" can be tested after "#define" is executed. The problem is that "#define" can't be inside main() function. I do not wish...
2
by: Andreas | last post by:
Hi! I'm using an IplImage library from camellia.sourceforge.net, and the testbench calls a file only containing code like the one below. In cam_morphomaths_code.c the real computation is made,...
3
by: theotyflos | last post by:
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type;
9
by: pozz | last post by:
Hi all, I have the below #defines #define NUMBER1 30 #define NUMBER2 50 #define SUM (NUMBER1+NUMBER2) #define STRING1 "Byte: \x30" #define STRING2 "Byte: \x50"...
34
by: BQ | last post by:
Hello Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant, is greater than 35, it returns 56, if not, 20. I would like that at compile time, not at run time. ...
17
by: niraj.tiwari | last post by:
What is meaning of the following define:- #define x(argl...) x1(##argl)
71
by: David T. Ashley | last post by:
Where is the best place to define TRUE and FALSE? Are they in any of the standard include files, ever? Do any standards apply? What I've traditionally done is something like: #ifndef...
6
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
23
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
2
by: badc0de | last post by:
Hello.. a header file of one of my project has macro definitions like this (for example) #define PART_A_SORT_1_LABEL_STRING1 100 #define PART_A_SORT_1_LABEL_STRING2 200 #define...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.