473,889 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

#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 29211
#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*******@yaho o.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.WriteLi ne() 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*******@yaho o.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.v b" 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
8937
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 to create multiple functions which they look almost identical in C++ source code. The C++ compiler should be able to compile one Test() function into two almost identical functions before they are translated into the machine language object. ...
2
5599
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, but I don't understand where cam_morphomaths_code.c is included and how to set what parameters to use in the testbench. How does this code execure? I don't understand a bit...
3
10597
by: theotyflos | last post by:
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type;
9
3099
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" If I change NUMBER1 and NUMBER2 I must change STRING1 and STRING2 consequently.
34
3226
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. So: #define FUNCT(x) x>35?56:20
17
2788
by: niraj.tiwari | last post by:
What is meaning of the following define:- #define x(argl...) x1(##argl)
71
33274
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 (TRUE) #define TRUE (1)
6
27941
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
3934
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
2305
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 PART_A_SORT_1_LABEL_STRING3 300 #define PART_A_SORT_1_LABEL_STRING4 400 #define PART_A_SORT_1_LABEL_STRING5 500
0
9967
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10895
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10443
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7998
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5830
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3256
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.