Home > Microsoft .Net Development Tips > ARCHIVE: Tips & Tricks > Control Naming
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ARCHIVE: TIPS & TRICKS

Control Naming


John Smiley
07.18.2000
Rating: -2.29- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Control Naming

Have you ever wished you had named a Visual Basic control by another Name -- or come across a project where the original programmer accepted all of the default control names -- such as Command1, List1, Text1, etc.

Changing the name of a control is easy -- you just need to open up the Properties Window for that control and change the Name property. However, what happens to the code associated with that control won't make you happy!

The code seems to disappear -- in actuality, any event procedure associated with the originally named control is relegated to the General Declarations Section of the form. As a result, when you run your program, that code is never executed.

So how do you "get the code back"?

The code hasn't really gone away -- all you need to do is find the event procedure in the General Declarations Section of the form -- and then change the "control name" portion of the Procedure header to the new name of the control.

For instance, if you had this code in the Click Event procedure of a Command Button named Command1...

Private Sub Command1_Click()

Msgbox "I love V

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
ARCHIVE: Tips & Tricks
SearchVB wants your tips
Find out what VS.NET modules are installed
Retrieving icons from an EXE-file
Toggling Boolean values
VS.NET multiple tabbed windows
Set the value of a DataField in code behind
Easy grid design
Open using last Visual Studio.NET layout
Save development time by using inherited forms
Reusing code in VS.NET

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


B"

End Sub

and then renamed the control to cmdOK -- VB `moves' this code to the General Declarations Section of the Form.

All you need to do is modify the procedure so that it looks like this...

Private Sub cmdOK_Click()

Msgbox "I love VB"

End Sub

Now, VB will once again associate this code with the command button -- and when you run your program, the code will execute -- just like before.

By the way, some of my fellow programmers rename their event procedures prior to changing the name of the control. Either way, the effect is still the same -- the code will be associated with the newly named control.

***********************************************************************
Written by John Smiley, MCP, MCSD and MCT, author, and adjunct professor of Computer Science at Penn State University in Abington, Philadelphia University, and Holy Family College. John has been teaching computer programming for nearly 20 years.

John Smiley is president of Smiley and Associates, http://www.johnsmiley.com/smass/smass.htm a computer consulting firm located in New Jersey.

Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts