Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Accessing vb.net controls using a concatonation of data elements to determine the control name to be called

Posted on 2003-12-02
6
Medium Priority
?
256 Views
Last Modified: 2010-04-17
vb.net Window forms controls
I call out to a database for the name of a control to determine where on the form the control will go. however i cannot convert the name of the control that i get from my sql to a point where the window's form recongnizes which control i'm requesting action on . here is an example of my code.

the sql brings in the tabname and the control name
i string them together  + the "txt" to get the name of the control

dim mystring as string
mystring = "txt" & TabName & ControlName
mystring.text = "I found the control"

i have tried other types besides string to concatenate the sql names and the "txt" but to no avail.

what can i do to dynamically call the name control i want to use.  I don't want to use case statements.
0
Comment
Question by:btreiber
  • 4
5 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 9862073
I wish I were in front of a NET box to test this, but..

foreach (Control x in y)
            {
            if (x.name==WhatImLookingFor)  x.text="FoundIt!";
            }
0
 

Author Comment

by:btreiber
ID: 9863075
thanks cookre, but I can't code this in C  and i don't want to do if  or loop statements because i have over 70 controls i have to handle like this.  any other suggestions.
0
 
LVL 22

Expert Comment

by:cookre
ID: 9863436
I've not done much with VB.NET, so this may be just a pipe dream, but..

If the target controls could be made into a collection, and if VB.NET has associative arrays, then you would set up an associative array subscripted by control name whose entries are indices into the control collection, e.g.,

CtrlArr("Button1")=0
...
CtrlArr("Button73")=72;
...
CtrlCollection(CtrlArr(strButtonName)).Text="Yippee!"

Yeah, I know, lots of ifs.

Let's see what I can dig up.
0
 
LVL 22

Accepted Solution

by:
cookre earned 600 total points
ID: 9863554
Ok, in VB.NET it's not an associative array, it's a hash table, and it looks like you could twist it to your purposes:
http://visualbasic.about.com/library/weekly/aa071203a.htm
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Simple Linear Regression
Introduction to Processes

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question