473,508 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

referencing variables PLEASE HELP ME!

Tricky

I'm trying to do the following
string sString = "Here is a test string";
string sFieldRef = "sString";
MessageBox.Show(sFieldRef); //How do I get this line to display: Here is a
test string instead of just sString???
// I am trying to access the
value of sString via sFieldRef
I want the messagebox to show what's stored
in sString (Here is a test string) but by
only using sFieldRef.

I know in Clipper, this is referred to as Macro Expansion.
Not sure how to do this in c#

Thanks in Advance,

Chris
Nov 15 '05 #1
5 1290
Hi,

seems like you need something like a string table, right ?
Just use a Hashtable (or a more memory efficient mapping) to store the
relation between the reference string and the target string.
You do have the query the hashtable everytime to get the target string. No
pain, no gain, of course.
You should also consider using constant integers as the reference. Much
more time and space efficient.

Greetings,

Bram.
"name" <na**@place.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
Tricky

I'm trying to do the following
string sString = "Here is a test string";
string sFieldRef = "sString";
MessageBox.Show(sFieldRef); //How do I get this line to display: Here is a test string instead of just sString???
// I am trying to access the value of sString via sFieldRef
I want the messagebox to show what's stored
in sString (Here is a test string) but by
only using sFieldRef.

I know in Clipper, this is referred to as Macro Expansion.
Not sure how to do this in c#

Thanks in Advance,

Chris

Nov 15 '05 #2
"name" <na**@place.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
Tricky

I'm trying to do the following
string sString = "Here is a test string";
string sFieldRef = "sString";
Uh, how about just assign the sString variable to the sFieldRef variable?
Like:

string sFieldRef = sString;

by using the quotes, you are just assigning a string, "sString", rather than
the value that is stored there.
MessageBox.Show(sFieldRef); //How do I get this line to display: Here is a test string instead of just sString???
// I am trying to access the value of sString via sFieldRef
I want the messagebox to show what's stored
in sString (Here is a test string) but by
only using sFieldRef.

I know in Clipper, this is referred to as Macro Expansion.
Not sure how to do this in c#

Thanks in Advance,

Chris


Nov 15 '05 #3
I can't do that because I will be reading from a file the names of fields
ie:

say in my program I have a class that has three variables:
sName,sAddress,sPhoneNumber

I will have a class function that will created a formatted string based on
the order specified by
a text file.

for example, if my program reads from a file that looks like:

file.txt
------------
sAddress
sName
sPhoneNumber

then when I call my output class function, it should display something like
123 First Avenue
Bob Jones
(555) 666-7777

if I change file.txt to look like this:

file.txt
------------
sPhoneNumber
sAddress
sName

then my class output function will display
(555) 666-7777
123 First Avenue
Bob Jones

Thanks,

Chris
"Gary Morris" <gm*******@carolina.rr.com> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl...
"name" <na**@place.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
Tricky

I'm trying to do the following
string sString = "Here is a test string";
string sFieldRef = "sString";
Uh, how about just assign the sString variable to the sFieldRef variable?
Like:

string sFieldRef = sString;

by using the quotes, you are just assigning a string, "sString", rather

than the value that is stored there.
MessageBox.Show(sFieldRef); //How do I get this line to display: Here
is a
test string instead of just sString???
// I am trying to access

the
value of sString via sFieldRef
I want the messagebox to show what's stored
in sString (Here is a test string) but by
only using sFieldRef.

I know in Clipper, this is referred to as Macro Expansion.
Not sure how to do this in c#

Thanks in Advance,

Chris


Nov 15 '05 #4
I would recommend the Hashtable approach specified by Bram first off. However,
you can use reflection to achieve the same goal. If the field is sAddress you
can
use Type.InvokeMember() with the appropriate overloads to get the value.

You can't do macro expansion, because this is macro expansion at run-time, not
macro expansion in the generic sense that is normally done as a precompilation
step.

--
Justin Rogers
DigiTec Web Consultants, LLC.

"name" <na**@place.com> wrote in message
news:PP********************@twister.tampabay.rr.co m...
I can't do that because I will be reading from a file the names of fields
ie:

say in my program I have a class that has three variables:
sName,sAddress,sPhoneNumber

I will have a class function that will created a formatted string based on
the order specified by
a text file.

for example, if my program reads from a file that looks like:

file.txt
------------
sAddress
sName
sPhoneNumber

then when I call my output class function, it should display something like
123 First Avenue
Bob Jones
(555) 666-7777

if I change file.txt to look like this:

file.txt
------------
sPhoneNumber
sAddress
sName

then my class output function will display
(555) 666-7777
123 First Avenue
Bob Jones

Thanks,

Chris
"Gary Morris" <gm*******@carolina.rr.com> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl...
"name" <na**@place.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
Tricky

I'm trying to do the following
string sString = "Here is a test string";
string sFieldRef = "sString";


Uh, how about just assign the sString variable to the sFieldRef variable?
Like:

string sFieldRef = sString;

by using the quotes, you are just assigning a string, "sString", rather

than
the value that is stored there.
MessageBox.Show(sFieldRef); //How do I get this line to display: Here

is
a
test string instead of just sString???
// I am trying to access

the
value of sString via sFieldRef
I want the messagebox to show what's stored
in sString (Here is a test string) but by
only using sFieldRef.

I know in Clipper, this is referred to as Macro Expansion.
Not sure how to do this in c#

Thanks in Advance,

Chris



Nov 15 '05 #5
Ah, that makes more sense. I was looking at the code and
it just seemed unusual that the field name was in quotes.
That would have just assigned the string in quotes to that
variable, but I see now how this is supposed to work. Good
suggestion.

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:O6**************@tk2msftngp13.phx.gbl...
I would recommend the Hashtable approach specified by Bram first off. However, you can use reflection to achieve the same goal. If the field is sAddress you can
use Type.InvokeMember() with the appropriate overloads to get the value.

You can't do macro expansion, because this is macro expansion at run-time, not macro expansion in the generic sense that is normally done as a precompilation step.

--
Justin Rogers
DigiTec Web Consultants, LLC.

Nov 15 '05 #6

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

Similar topics

2
1663
by: xcomm | last post by:
Hi All, <?php $vars= array("_SERVER","_SERVER","_SERVER","_SERVER","_SERVER","_SERVER"); foreach($vars as $var) { if(isset($$var))echo("$var: ${$var}<br>\n"); } ?> php.net:
16
34535
by: Robert Mark Bram | last post by:
Hi All! Is there a way to reference a window by name without doing something like this: open (, 'windowName'); The open method will open a blank window if there is no window with such a name....
12
1941
by: Mark Broadbent | last post by:
Hi guys, just going through remoting at the moment and a couple of questions relating to .net in general has surfaced. Firstly I have seen in the designer that for the namespace and many of its...
6
11268
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
5
1794
by: Amelyan | last post by:
I am struggling here trying to determine what is a good programming practice as far as referencing your URLs. When you use Response.Redirect, do you use 1) Hard-coded string --...
3
1185
by: lwoods | last post by:
Example: $x=array('a'=>'ant','b'=>'boat'); $s='a'; $y='$s'; echo $x; I want to echo the value of key 'a' by indirectly referencing it via the variable $y. The above is NOT correct, I know.
2
4041
by: Axel | last post by:
Hi, a question about something that seems very simple at first glance: is it possible to reference other controls of a subform in a query window without referencing through the parent form? I...
2
1430
by: HankD | last post by:
Hi, I am having a problem with instantiating two custom objects so they DO NOT point to the same memory location. What is happening is that changes I am making to my object1 are changing object2. I...
0
7223
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
7115
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
7489
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...
1
5047
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...
0
4705
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...
0
3191
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...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
414
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...

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.