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

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

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.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.

734 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