Solved

For each in Me.Controls

Posted on 2006-07-17
8
245 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
  • 3
  • 3
8 Comments
 
LVL 62

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 62

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 62

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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