473,397 Members | 1,961 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,397 software developers and data experts.

Using a variable for a name

Given the following code:

Private Sub ButtonShowTheIntValue_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ButtonShowTheIntValue.Click

MsgBox(String.Format("TheClassInstance.TheInt = {0:G}",
TheClassInstance.TheInt))

End Sub

The code above displays a simple message box that shows the value of the field
TheInt in the object TheClassInstance. If I rename the object or the field in
it's declaration I'll get an easily fixable error. However, there's the risk
of correcting the name of the variable, but leaving the string literal
unchanged. Is there somehow a way to replace the string literal
"TheClassInstance.TheInt" with a variable so that I would get a compilation
error if the field's name was to be changed in its declaration?




Nov 21 '05 #1
1 1225
AFAIK, no, there is no direct way. Reflection allows you to discover types
fields at run time, but you need the name to identify an element. The only
workaround would be to attach an attribute to the field and use Reflection
at run time to locate the element whose attribute is that and then retrieve
the name.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Alex" <pl*****@no.mail> escribió en el mensaje
news:eb**************@tk2msftngp13.phx.gbl...
Given the following code:

Private Sub ButtonShowTheIntValue_Click(ByVal sender As System.Object,
ByVal e
As System.EventArgs) Handles ButtonShowTheIntValue.Click

MsgBox(String.Format("TheClassInstance.TheInt = {0:G}",
TheClassInstance.TheInt))

End Sub

The code above displays a simple message box that shows the value of the
field
TheInt in the object TheClassInstance. If I rename the object or the
field in
it's declaration I'll get an easily fixable error. However, there's the
risk
of correcting the name of the variable, but leaving the string literal
unchanged. Is there somehow a way to replace the string literal
"TheClassInstance.TheInt" with a variable so that I would get a
compilation
error if the field's name was to be changed in its declaration?





Nov 21 '05 #2

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

Similar topics

1
by: Scott | last post by:
I have an XML Document in a format like: <Variable name="Bob">ABCDEFG</Variable> <Variable name="Steve">QWERTYUI</Variable> <Variable name="John">POIUYTR</Variable> <Variable...
3
by: Sandros | last post by:
Background: I'm collecting usability statistics for a group of applications. Each count has the following attributes: date, application, major heading, minor heading, count. My intent is to pull...
1
by: eric | last post by:
I am using an xml file as a relational data store like the following (original data is much larger): .... <variable> <id>A</id> <name>VarA</name> <description></decription> </variable>...
0
by: Fraser Dickson | last post by:
I am building a web based system using ASP.NET and VB.NET which has to interact with a web service which uses XML WDDX packets. I have been given the XML Packet Specification by the Web Service...
7
by: William Apple | last post by:
Despite the fact this deals with webservices I believe it is a VB question. I am working on a test application that passes data to a webservice. The webservices takes a variable type that is...
13
by: Andy Baxter | last post by:
Can anyone recommend a good online guide to using objects in javascript? The book I bought (DHTML Utopia) suggests using objects to keep the code clean and stop namespace clashes between different...
2
by: 张韡武 | last post by:
We have preffered language set as variable in xslt: <xsl:variable name="preferred_language"> zh </xsl:variable> Data: <name xml:lang="de">Raw Materials (Mining incl.)</name> <name...
4
by: Jean-François Michaud | last post by:
Hello, I've been looking at this for a bit now and I don't see what's wrong with the code. Can anybody see a problem with this? Here is an XSLT snippet I use. <xsl:template match="graphic">...
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
7
by: garyusenet | last post by:
This is the first time i've worked with openfile dialog. I'm getting a couple of errors with my very basic code. Can someone point out the errors in what i've done please....
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: 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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.