473,386 Members | 2,050 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,386 software developers and data experts.

Setting variables at Compile Time using #Const

Is it possible to set a variable with the value of a compile time constant.

Example:

#Const MODE_STR = "Mode1"

dim strMode as String = MODE_STR

Obviously this doesn't work. Is there a way to achieve the same thing???
--
: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
: my email address zf****@pbqrvafvtug.com is encrypted with www.rot13.org
Nov 20 '05 #1
1 3095
Hi Michael,

Unfortunately, you can't do exactly what you want. #Const constants can
only be used in #If directives. For example:

#Const TEST_CONST

some code

# If TEST_CONST = "TEST" Then

some conditional code

# End If

You can do close to what you want in one of two ways. First something like

#Const MODE_STR = "Mode1"
# If MODE_STR = "Mode1" Then

Private Const MODE_STR = "Mode1"
# End If

Dim strMode As String = MODE_STR

It's probably simpler, however, to just use Const.

Private Const MODE_STR = "Mode1"

Hope this helps,
Craig VB.Net Team

--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).

--------------------
From: "Michael Fitzpatrick" <mm*****@codeinsight.com>
Subject: Setting variables at Compile Time using #Const
Date: Tue, 24 Feb 2004 09:02:03 -0800
Lines: 16
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <eU**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 165.152.34.237
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:184377
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Is it possible to set a variable with the value of a compile time constant.

Example:

#Const MODE_STR = "Mode1"

dim strMode as String = MODE_STR

Obviously this doesn't work. Is there a way to achieve the same thing???
--
: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
: my email address zf****@pbqrvafvtug.com is encrypted with www.rot13.org


Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
5
by: Amogh | last post by:
Hi, My question is related to setting freed pointers to NULL. After freeing a pointer: 1) Should the freeing routine also be responsible for setting the pointer to null? 2) Or, should the...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
4
by: junky_fellow | last post by:
Hi guys, Consider the following statements. const int *ptr; /* ie the contents pointed to by ptr cannot be changed */ My question is how/who prevents the contents from being modified ?...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
2
by: Ranganath | last post by:
Hi, Why is there a restriction that only integral types can be made static constant members of a class? For e.g., class B { private: static const double K = 10; };
8
by: fabian.lim | last post by:
Hi, I have a question on constant variables. In the following code snippet, I have a function assign() that takes in an iterator to the private variable v, the number of stuff to assign (int n),...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.