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
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

615 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