|
-
Sep 16th, 2003, 03:44 AM
#1
Thread Starter
Lively Member
How to Reference a control through a variable ?
I am working on a small project and I need to reference controls that they are created during runtime. The name of the control is saved in a variable, is there a way to refer to this control.
Example
dim A as string
dim B as textbox
somewhere in code A="SOMENAME", this name is created randomly
B= new textbox
B.name=A
pnlcontrols.controls.add(B)
Later in the program I need to refer to the SOMENAME.text
but the value SOMENAME is held in the variable A, A.text is not possible. Is there a way to do this. I need to replace A with the value of A at runtime.
Thanks
-
Sep 16th, 2003, 10:00 AM
#2
The name isn't going to do much for ya. Why are you not just storing a reference to the control itself instead of its name?
-
Sep 16th, 2003, 10:11 AM
#3
Thread Starter
Lively Member
That was an option but I tried to look up how it is done and could not find an easy way so I thought that it is not possible or very difficult to do.
If you can guide me how to do this or where to look up in the help I will very much appreciate it.
many thanks.
-
Sep 16th, 2003, 10:16 AM
#4
When you create the new textbox then you are probably already assigning it to a variable you just have to persist that variable instead of just the name.
What does this mean 'somewhere in code A="SOMENAME", this name is created randomly'?
Did you create a control/textbox in there somewhere or just a name?
Post the code you are using to make the new textbox.
Controls are objects like everything else so they already are variables and you can assign them to other variables too if you want.
VB Code:
Dim txt As New TextBox
Dim a As TextBox
a=txt
'now both a and txt reference the same textbox instance
-
Sep 16th, 2003, 10:28 AM
#5
Thread Starter
Lively Member
Thanks for your help but I connot post the code as I am not at home.
What I am doing is creating controls, actually combo boxes to be used with crystal and I give each the name of the crystal parameter.
suppose parameter name was FromDate
dim mycont as combo
mycont.name= paramater.name
pnlparameters.controls.add(mycont)
This will create the parameters.
later I need to refer to mycont to get its value, so from the parameter name FromDate I need to get the value of mycont whose name is FromDate.
-
Sep 16th, 2003, 10:49 AM
#6
Different controls can have the same name or no name at all so storing the name of the control will do you no good unless you can reference either the control or the container of the control.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|