how to get variable value by using variable name as parameter???

I have a problem as following;

I want to give my variable name as parameter to a function, then get value of that variable.

Like this;

dim myValue, myVariable, result  as string
myValue = "demo"
myVariable = "myValue"

result = SomeMagicFunction(myVariable)

then value of result sould be demo

I know that is an interesting case. But i need this. :(

Please help me !!...

8/2/2006 9:45:29 PM 91979 articles. 4 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 26

If you explain the situation where it is going to be used, there may be some other alternative solution to it. One solution is to store value in a property of a class or structure and then later on use reflection to retrieve value of the property by using the name of the property supplied as function parameter.


8/3/2006 9:19:40 PM
You might want to try out the Dictionary collection if you're using framework 2.0. It could just solve your issue.
//Implement the collection here
Dictionary<string, string> coll = new Dictionary<string, string>();

string myValue, myVariable;
myValue = "demo";
coll.Add("myValue", myValue);

myVariable = "myValue";
result = SomeMagicFunction(myVariable);

//and this could go into SomeMagicFunction return coll[myVariable];
This is of course the basic idea of how you'd go about accomplishing the task. I am presuming that you know how to assign dynamically the string myValue's object name into myVariable (myVariable="myValue"), and you can easily replace however you do it in the coll.Add("myValue", myValue) line.

Visit for a comprehensive example of Dictionary Operations.


So simple... yet so effective.
My "Life"ly Blog
8/3/2006 10:18:55 PM

Similar Artilces:

How can I get a "variable value" from the "variable name"
Hi All, How can I get a "variable value" from the "variable name" ? For Example: ClassDefinition cd_def VariableDefinition vd_def cd_def = this.classdefinition For li_i = 1 To UpperBound (cd_def.VariableList) vd_def = cd_def.VariableList[li_i] MessageBox ("Variable Name: ", ) MessageBox ("Variable Value: ", "??????????") Next Thanks, Gustavo Which value do you expect to get? pbm_thisusuallydoesnothelp:-)) Philip Salgannik <Gustavo> wrote in message

How to get session variable value into a static variable
Hi, On page preinit i am adding few session variables. Now i want to retrive these session variable values into my static variables. protected void Page_PreInit(object sender, EventArgs e) {Session.Add("T", "Default"); Session.Add("T1", "Red"); Session.Add("T2", "Blue");   }   i have few static variables which shud contain these vaules.  public string TT; public string TT1; public string TextForeColor =sess = "#FFFFFF";   i want to get T value into TT ... T1 into TT1..and so on &n...

Getting value from a variable when name is in a string
I have a string that contains a variable name. I need to get the value contained within that variable named in the string. Help! Thanks Example: l_s_stringvar = 'g_i_limit' g_i_limit = 5 I want f_getvalue(l_s_stringvar) to return 5. What do you need this for? in our reports we are allowing the users to specify column labels for user defined columns. We put these in global vars. I need this function so I can code the datawindow (reports) to get the column labels from the global variables. Does this make sense? Nope, it does not. Why are they in global variable...

Using OneWay parameter not getting server variables
I have a web service with the following definition: _ _ Public Sub FileTransfer() I know that Required is deprecated. The issue that I having is that I can not seem to get the server variables. I tried all of the following but they do not appear to be created: Context.Request.ServerVariables("REMOTE_ADDR") Context.Request.UserHostAddress I figured I would at least do a count of the number of items in the ServerVariables array: Context.Request.ServerVariables.Count I through a tyr catch around this and the exception is the the object has not be...

Getting variables from a post or get?
Sorry for the newbie post, but i am from a PHP world. Im now learning ASP.NET.Im having a bit of problem figuring out how to get/post a variable on an input field. All i want to do is, get the value from an input form and display it again on the page. Here's my code.. <form id="form1" runat="server" acceptcharset="utf-8"> Your name: <input id="name" name="name" type="text" /> <asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="Default.aspx" /> </form> All i want is to get the value of name and display it on the page it self. How can i do that...

Use variable as variable name.
If seen it in other languages but don't know how to achieve this in  Is there a way to use a variable as the variable in and visual basic? For example, rather than using this:myDataSource.DataSource = dsDo something like this:myVariable = "myDataSource"interpret(myVariable).DataSource = ds   ' Allthough interpret is not a defined functionThanks for any help!  There are advanced ways of doing this using System.Reflection. However, for all practical purpose, no, this is not possible. .NET is a strongly typed language, which means it...

Getting encrypted query string parameter value into a variable.
 Hi,   http://localhost/isolutions_source/Startup/RequisitionRecruitment/Forms/OfferLetterAcceptReject.aspx?erSBUi2Lo4usDg6iQAYEjG9f6qseNyxzpYmuhgxKwwBmkoqM8tptWJ+Ro5NivYoluZOz5Z8Dktj+MqEAqV1+Ko2dM3l/djKT   In the above link i am getting a encrypted paramenter value.. Now i want that decrypt that parameter,so that i can use that in my new form.... So plz help by giving me some solution.. Thanks in advance.        You must know the Encryption algorithm. Then and then you can Decrypt this String. - Please check your URL creator code ... - just try...

Getting Value from Client-side InputBox to .net variable
hi, im doing a login page for our timekeeping. Since there's no msgbox available on, im doing it dynamically via javascript. How do i Get the value frm a dynamically written javascript (such as inputbox) to a .net variable? here's the logic of my program, user logs in hits the button and sub-routine Login will be fired, if user is late -- call Check_Late Sub, this is whre the client-side script was built -- then after that i wanted to be able to get the value from an inputbox. '// if button login clicked Sub Login(Sender As Object, E As EventArgs) .......

How do variable names like [$NG_ALBUM_NAME$] get replaced with their values?
I'm working on customizing the look of nGallery by creating my own theme and editing some of the ASPX files. I want to have the title of the album listing page be the [$NG_ALBUM_NAME$] variable instead of the [$NG_HEADER$] variable name which it is currently. However, when I replace [$NG_HEADER$] with [$NG_ALBUM_NAME$] in the source for the file AlbumListing.aspx the resulting website doesn't have the correct value for the album name - the actual variable name shows up instead ("[$NG_ALBUM_NAME$]"). Where is the code that does that replaces the variable names with their...

Updating/getting values from datagrid in C# with variable parameters
HiI am new to the world of aspx, .net and C#.In aspx .net 2.0. I am trying to work out how to get a datagrid to perform an update. Using Visual Developer I have successfully added the control and specifed a select statement to return data via my SQLData Source. This works fine. However having specifed the control as editable I would like to perform an update through the datagrid and SQLDatasource. I see in the properties for the SQLDatasource object I can specify my update statement.However I do not understand how to get that update statement to have variable values and how newly entered val...

Field1 value --> variable name ; Field2 value --> variable value (C# code behind)
 I would like to add quantities to variables based on two fields in a table.  The table includes two field names: ingredient, weight.  Assume a simple formulation: add 50 lbs water, add 20 lbs eggs, add 10 lbs water, add 5 lbs salt.The table would have: water, 50 eggs, 20 water, 10 salt, 5The variables water, eggs, water and salt have already been defined. I want something that will cycle through and add the quantities (lbs) to the variable. Ingredients can appear more than once in a formulation--notice that water appears twice and at the e...

Get value of variable
 Hi all, I have a problem such as (C#, webbase, store procedure):1. I have 3 pages (aspx):       +  the fist page (login.aspx): when user Login have 2 variable: user and password      +  the second page (accept term): user modify password and accept term of service, have 3 variable oldpassword, changepassword, term          i use store procedure Update user Set password=@password where mobile=@mobile         Now i want value of variable user in The fist page to update, b...

Using GET Variables
Hello all,I am a PHP developer, slowly getting into ASP.NET but one thing I have been trying to do is learn how to use GET variables in ASP.NET (Such as, Defaul.aspx?ID=1234&Name=Someone). Can someone tell me how you use them or direct me towards a tutorial that shows the use of them.Thanks! Hi, Accessing querystring happens with Request.QueryString["nameofvariable"] which for example with your Defaul.aspx?ID=1234&Name=Someone when used like this on the requested page string s = Request.QueryString["Name"]; after that s would contain "Someone". Here is small tutorial about...

get variable name
Hi! it's seems to be vwry simple, but I look for it to long time: I want go through variable names and set, for example, some values to each string Var1; string Var2; string Current_Var; for(i=1; i<=2; i++) { Current_Var = FindControl("Var"+i); Current_Var = i; } but this FindControl is only for ControlElements. Is any function for variables like this? Thanks hello, why do u want to use Findcontrol ? can't u just use an array of variables ? string[] var = new new string[2]; for(i=1; i<=2; i++) { Current_Var = v...

Web resources about - how to get variable value by using variable name as parameter??? -

Parameter - Wikipedia, the free encyclopedia
A parameter (from the Ancient Greek παρά , "para", meaning "beside, subsidiary" and μέτρον , "metron", meaning "measure"), in its common meaning, ...

fb_source Parameter - Facebook-Entwickler
This document lists the complete list of values for the fb_source parameter that is returned with th...

Google Webmaster Tools Parameter Handling - Flickr - Photo Sharing!
You aren't signed in Sign In Help Home The Tour Sign Up Explore Explore Home Last 7 Days Interesting Popular Tags Calendar Most Recent Uploads ...

Cat 8: TIA performance standards committee chairman previews parameters of forthcoming twisted-pair cable ...
Category 8, the next-generation twisted-pair cabling specification, is still in development, but the outlook looks quite positive that it will ...

Philippine president asks for 'parameters' of Mayon Volcano tours
Philippine president asks for 'parameters' of Mayon Volcano tours People's Daily Online ... 26, 27, 28, 29, 30, 31. Jan, Feb, Mar, Apr, May, ...

Alternatives to boolean parameters
... ) { PrintLine ( item . Name ); if ( printDetails ) { PrintLine ( item . Description ); } } } Aha! Now can see that the boolean parameter ...

Exporting Error (Error in Parameter...: Apple Support Communities
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability ...

Apple tech monitors device aging, adjusts operating parameters to ensure optimal performance
... describing a method of monitoring the aging of a device's electronics, comparing the data with a global average and modifying operating parameters ...

Is it poor programming practice to pass parameters as objects?
... a free, community-powered network of 100+ Q&A sites . Risser asked: So, we've got a guy who likes to write methods that take Objects as parameters, ...

Parameter Short Film Competition sponsored by Grolsch
Grolsch presents Parameter The A.V. Club Short Film Competition Please Enter Your Date of Birth Ineligible entry Enter For people over the age ...

Resources last updated: 12/8/2015 12:47:25 AM