Solved

For each in Me.Controls

Posted on 2006-07-17
8
257 Views
Last Modified: 2011-09-20
Hi,

I got many buttons okay. Lets say 6 with their names:   Button1, Button2, Button3 etc.
I want to manipulate for example Button4.

I would like to manipulate that way:

dim str = "Button", x as Integer = 1
("Button" + x).Name .....

I know, we cant do that. I know its possible by the way of a For each than you check the ctrl.Name , then if its then same, you can play with it. But I tought it was not 100% efficiant.  Is there a way like my ("Button" + x)  to call that button other than a for each, other than calling Button4.name too ... the thing is, it will be never the same button. It might change that why I was needed that integer (x) or a for each

Thanks
0
Comment
Question by:PhilippeRenaud
[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
  • 3
  • 3
8 Comments
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 150 total points
ID: 17122818
Hi PhilippeRenaud;

Place the controls in a Hash Table with the key as the controls name and then you can get the control using its name.

Fernando
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17122823
What version of .Net are you using 2003 or 2005?
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17122834
2005
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Accepted Solution

by:
Jeff Certain earned 350 total points
ID: 17122855
Then use Dictionary(of string, button) and put the buttons in the dictionary using the control name as the key...

Imports system.Collections.Generic
Dim controls as Dictionary(Of string, button)

private function GetButton(buttonName as string) as button
If controls.ContainsKey(buttonName) then
  return controls(buttonName)
else
  return nothing
End If

End Function
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17122882
In 2005 you can do this

     Dim btn() As Control = Me.Controls.Find("Button5", True)

Fernando
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17122895
I wanted to split points, But i clicked at the wrong place
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17122999
Well, the hastable do the same thing i guess, but I found it great to do it with a dictionnary.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 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