School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,159 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,529 people online right now. Registration is fast and FREE... Join Now!




Naming Guidelines

 
Reply to this topicStart new topic

> Naming Guidelines, Variable & Controls need names.

AdamSpeight2008
Group Icon



post 7 May, 2009 - 04:36 AM
Post #1


Naming Guidelines

To help with the readability of code it is advisable to give your variables names that are meaningful.
In the following example Calculating the amount of pay based on hours worked and a hourly rate.
Which is easier to read and understand;-
CODE

C=A*B

or
CODE

PayPacket = HourlyRate * HoursWorked

This isn't restrict to variables I would suggest you apply it to your controls as well.
When you Drag & Drop a control from the toolbox on to the form design, the designer automatically gives your control a name. E.g.

TextBox1
TextBox2
TextBox3
PictureBox1
Button1
Button2

This is ok for uniquely identifying them but useless for readability, as they have no meaning or context.
In the properties windows, clicking in the name property

and give them better one.

I generally use the follow format for my controls.
Format: <3letters>_<Name>

Frm Form
But Button
Lbl Label
Txt Text
Pic PictureBox
Pro ProgressBar
Lst Listbox

A few examples;

Frm_Main
Frm_Recipt
But_CalculateVat
But_Cancel
But_OK
Lbl_Author
Txt_AuthorName
Txt_BookTitle
Txt_Price
Pic_FacePicture


So from now on you gonna be a meaningful variable & control naming code ninja. ph34r.gif
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 05:52PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month