Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2008, 02:46 PM
Registered User
 
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Procedure Parameters

      I am creating a Generic Public Procedure that will loop through all of the controls on a form and if a control is a (Type button and button.text = "A particular button" )I want to disable it.

      My question is should I pass the Form that I am looping through its controls to this Generic procedure? Does there exist a more efficient means to accomplish this coding task.

Thanks In Advance ...

John Smith
 
Old May 5th, 2008, 08:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You'll need to pass the the form's controls collection at a minimum. However, given that object references are just pointers, I don't imagine that there is any more or less efficient way to do it. The only thing you could improve I would think is the point at which you start searching. There's little need to recurse over some branches of the control tree if you know you needn't. However, for this type of generic behavior you'll need to start at the top and look everywhere.

I've implemented similar functionality and have created the method to accept a control collection. This seemed like the natural candidate to cleanly support the necessary recursion.

One thing you might consider is to implement this even more generically and create a procedure that simply looks for all controls of some parameterized type. Create an actual Generic method such as:
Code:
   public void ForEachControl<T>(ControlCollection controls, ControlActionDelegate doWork)
The method can do the control type test and then call "doWork" when it encounters the type desired. Then your delegate can do the test and appropriate manipulation. This way you can reuse the method for any action needed for any control type. This becomes even more elegant when you use a simple anonymous delegate right in the method call.

-Peter
compiledthoughts.com
 
Old May 5th, 2008, 12:10 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Asp_Developer,

Thanks again for the personal message. However, I'd prefer that you continue discussion on the forum instead as it helps to manage the conversation and others can learn from your question.

You asked for more clarification on some of my suggestion.

If you would like more explanations on concepts found in my suggestion (such as delegates and generics) I'd recommend spending a little time searching for those terms. There is a search engine targeted specifically at .NET: http://www.searchdotnet.com . This is actually a restricted google search created by Scott Guthrie. You should be able to find ample discussions on any .NET concept there that will be far superior to what I might type out in a few minutes. Here's an article I found on generics while checking VB.NET syntax for the rest of my post:

http://www.ondotnet.com/pub/a/dotnet...vbnet_pt2.html

My apologies for not noticing that this was a VB topic, here's the method signature I suggested above in its VB.NET form (hopefully the generics are correct, I work in C#):


   Public Sub ForEachControl(Of itemType)(ByVal controls As ControlCollection, ByVal doWork As ControlActionDelegate)

doWork would be a delegate (method pointer) to a method you create that does the work you wish to for the control type you want to act upon. I'm sorry I can't provide a good code example. I don't work in VB.NET so I'd rather not mislead you with a bad example when you're likely to find some examples online by people who know VB.NET generics better than me.

-Peter
compiledthoughts.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure Parameters Blank brettdalldorf Crystal Reports 0 September 20th, 2007 02:17 AM
Odbc Parameters Stored Procedure jgrant ASP.NET 2.0 Basics 2 August 26th, 2007 10:21 PM
One textbox, Two Parameters, with Stored Procedure GailCG Classic ASP Professional 0 March 3rd, 2006 03:39 PM
Calling Stored Procedure with parameters zarina_24 Classic ASP Professional 4 March 2nd, 2006 11:57 AM
stored procedure with parameters Danmalam VB Databases Basics 0 February 27th, 2005 03:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.