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

Variable Inside Variable

How do I, if at all possible, reference a variable with another variable
in VB.NET?

For example, if I have a form with a textbox and a button. Type var1 in
the textbox

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button.Click

dim var1 as string
var1 = "Hello World"
msgbox( /// display the contents of var1 using what was entered in
the textbox /// )

End Sub

Is this possible?

Thanks!
Mar 20 '08 #1
2 1139
"Grant" <gr**********@gmail.comschrieb
How do I, if at all possible, reference a variable with another
variable in VB.NET?

For example, if I have a form with a textbox and a button. Type
var1 in the textbox

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button.Click

dim var1 as string
var1 = "Hello World"
msgbox( /// display the contents of var1 using what was entered in
the textbox /// )

End Sub

Is this possible?
Do you know why variable names have been invented? Do you know what
compiling means?
Armin

Mar 20 '08 #2
Hello Grant,

I wonder, for what would you need that?
If it's about your example, then it is unnecessary as you could
reference the text box directly.

TextBox1 contains the text "Hello World"

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button.Click

MsgBox(TextBox1.Text)

End Sub
Normally, I would not expect a user to know what variables are used in a
program. So, the input of a variable name which a user entered can match
the variable name in a program only by a very slight chance.

However, if there is only a limited number of variables used in your
program, you could list them in a ComboBox/ListBox and return the
content of that variable depending on the variable the user selected.
But consider, that variable names (e.g. var1, var2, var3) don't really
give much info about what the variable contains. Therefore, it might be
better to add the contents of the variables to the ComboBox/ListBox and
let the user choose from those.

Best regards,

Martin
On 20.03.2008 11:32, Grant wrote:
How do I, if at all possible, reference a variable with another variable
in VB.NET?

For example, if I have a form with a textbox and a button. Type var1 in
the textbox

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button.Click

dim var1 as string
var1 = "Hello World"
msgbox( /// display the contents of var1 using what was entered in
the textbox /// )

End Sub

Is this possible?

Thanks!
Mar 20 '08 #3

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

Similar topics

2
by: Brian Leair | last post by:
I am using "from MyModule import *", (yes, yes, I know) MyModule has a variable "g_my_var" at the "global" scope. In the code that performs the import, I have a function that has the statement...
3
by: Thomas Matthews | last post by:
Hi, While coding programs, I cam about a conundrum regarding variables defined in an iterative loop. The issue is whether it is more efficient to factor the definition out of the loop or...
7
by: YGeek | last post by:
Is there any difference between declaring a variable at the top of a method versus in the code of the method? Is there a performance impact for either choice? What about if the method will return...
2
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
4
by: Ray | last post by:
Hello, I think I've had JavaScript variable scope figured out, can you please see if I've got it correctly? * Variables can be local or global * When a variable is declared outside any...
7
by: Max | last post by:
Please somebody can shed a light... How can I have a variable visible and modifiable, inside one and only webform? I mean , I d like to see that variable from all the Sub of that webform code,...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
14
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; int main() { int i;
4
Dheeraj Joshi
by: Dheeraj Joshi | last post by:
Hi, I was wondering is there any technique available, so we can access the global variable inside a function if we have a local variable inside the function with the same name as global variable. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...

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.