English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

My Korean professor said he does not use the prefixes anymore. But I have learned before that they are still important because I know its a good programming practice. What should I tell him to rebutt so that I can be able to help my other non-programmer classmates?

2007-03-07 14:18:40 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

You are referring to Hungarian notation, the use of a 2 or 3 letter prefix which identifies what type of control it is.

For example (for the benefit of other reading this)

a textbox called FirstName would be named txtFirstName


The advantage to this type of notation is that the intellisense of VB will show objects, methods and properties in alphabetical order. (Intellisense are the drop down boxes which pop up as you type the dot notation)

So if you have a large number of textboxes on your form they will naturally be grouped together in the intellisense listings.
This will aid you in finding a particular text box in the listing especially if you can't quite remember exactly what it is called at least you know where to look in the list.


Next Hungarian notation tells you what type of control you are dealing with.... Going back to my example above txtFirstName.

If you called it just FirstName how do you know it is a textbox and not some other type of control? FirstName could be a lable control or even a Button (click here to enter your first name)

Finally .... You are not charged anything for using three extra characters. (just a slight effort and some discipline to use some common abbreviation prefixes)

btn = Button
lbl = Lable
cmd = Command Button VB6
txt = TextBox
prg or pb = progress bar
mnu = menu
frm = form

2007-03-07 15:47:23 · answer #1 · answered by MarkG 7 · 0 0

At least for VB6 there is a very good reason why: to easily distinguish variables from controls.

As you maybe know, you can access a control property with different source code, but same effect:
Me.Text1.Text = "hello"
Me.Text1 = "hello"
Text1 = "hello"

Even assigning numbers to text boxes which will be automatically converted is ok:
Me.Text1.Text = 3
Text1 = 3

Prefixes make the source code more readable. See example that is self-explanatory in the first case and error prone in second:

Dim TotalPrice As Single
TotalPrice = Val(Me.txtPricePerUnit.Text) * Val(Me.txtUnits.Text)
Me.txtTotal.Text = TotalPrice

or

Dim TotalPrice As Single
TotalPrice = Val(PricePerUnit) * Val(Units)
Total = TotalPrice

2007-03-08 10:07:42 · answer #2 · answered by BataV 3 · 0 0

fedest.com, questions and answers