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
206 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

746 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

12 Experts available now in Live!

Get 1:1 Help Now