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
216 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
6 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

Expert Comment

by:cookre
ID: 9863478
0
 
LVL 22

Accepted Solution

by:
cookre earned 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now