VB.NET Naming Conventions for Controls

VB.Net apparently does not recommend the use of Hungarian notation for variables, properties, methods, etc. I haven't found any specific guidance on controls (i.e. lbl_Name, tbx_Name). Anyone have an authorative source for such guidance?
Who is Participating?
rfgkevConnect With a Mentor Commented:
They would probably say it can allow hackers to run code on your machine so install the latest windows updates immediatley :)
xmlnewbieAuthor Commented:
Not sure what you are trying to point out. If you are showing the Hungarian Notation for variables, that's not what I want. MS says that's out. I'm not using it anymore. I'm not sure about controls, though.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

it's entirely down to personal choice.
Alot of programming shops have their own standards that they expect their employyes to adhere to, to ensure that all of their work is consistent. There is nothing worse maintenance wise than trying to debug code written by 3 different guys (or gals) who each use different notation, etc..

Variables and Controls are both objects, so why use hungarian notation for one and not the other?
"Variables and Controls are both objects, so why use hungarian notation for one and not the other?"

Exactly.  There is no "authorative source for guidance" when naming controls/variables.  Hungarian notation is just a naming convention that Dr. Charles Simonyi of Microsoft came up with in the DOS days.  It's just a suggestion on how to name variables (and now controls).
xmlnewbieAuthor Commented:
The help files keeps saying not to use Hungarian for so many things. I just can't find anything about controls specifically.
I should maybe have rephrased that last one, Controls ARE variables. So although it is entirely up to the developer, it is generally considered to be best to be consistent in your coding.
xmlnewbieAuthor Commented:
What would MS say?
Arthur_WoodConnect With a Mentor Commented:
xmlnewbie>> let me ask you one VERY simple question:  If Microsoft said 'JUMP', would you ask 'How high?', on the way up?

Why is it important to you what Microsoft would say about your PERSONAL choice of naming convention in YOUR programs - and when they are compiled, the names that you CHOSE to use are no longer present in any case.  Are you suspecting the Microsoft is somehow spying on you as you write your code, and if you violte thier guidance, then Bill Gates will personally come to your office and whip you with a limp noodle?

The choice of naming convention is completely up to you (and possibly the guidelines of the shop where you work), and while Microsoft can offer an opinion, that is all it is, AN OPINION.  And like everything else, they are entitled to their opinion and you are entitlted to your opinion.

Microsoft has put a lot of naming recommendations into the FxCop documentation (not sure they have recommendations for controls).  Still it's a good place to see the MS recomendations:  http://www.gotdotnet.com/team/fxcop/
have you ever run FXCop against the FXCop exe? it produces some interesting results. Mainly stating that you should not catch System.Exceptions, and that alot of the methods are not used so should therefore not be coded.  The FxCopCommon dll is even better, "Member names should consist of correctly spelled words".
Bob LearnedCommented:
Once more into the breach my friends.  Another one into the dogpile.

Naming Guidelines from Micro$oft:


 Try following

 3D Panel      pnl      pnlGroup
Animated button      ani      aniMailBox
Check box      chk      chkReadOnly
Combo box, drop-down list box      cbo      cboEnglish
Command button      cmd      cmdExit
Common dialog       dlg      dlgFileOpen
Communications       com      comFax
Control (used within procedures       ctr      ctrCurrent
when the specific type is unknown)
Data control      dat      datBiblio
Data-bound combo box      dbcbo      dbcboLanguage
Data-bound grid      dbgrd      dbgrdQueryResult
Data-bound list box      dblst      dblstJobType
Directory list box      dir      dirSource
Drive list box      drv      drvTarget
File list box      fil      filSource
Form      frm      frmEntry
Frame      fra      fraLanguage
Gauge      gau      gauStatus
Graph      gra      graRevenue
Grid      grd      grdPrices
Horizontal scroll bar      hsb      hsbVolume
Image      img      imgIcon
Key status      key      keyCaps
Label      lbl      lblHelpMessage
Line      lin      linVertical
List box      lst      lstPolicyCodes
MAPI message      mpm      mpmSentMessage
MAPI session      mps      mpsSession
MCI      mci      mciVideo
MDI Form      mdi      mdiNote
Menu      mnu      mnuFileOpen
MS Flex grid      msf      msfClients
MS Tab       mst      mstFirst
OLE      ole      oleWorksheet
Outline       out      outOrgChart
Pen BEdit       bed      bedFirstName
Pen Hedit      hed      hedSignature
Pen ink      ink      inkMap
Picture      pic      picVGA
Picture clip      clp      clpToolbar
Report      rpt      rptQtr1Earnings
Shape       shp      shpCircle
Spin       spn      spnPages
Text box      txt      txtLastName
Timer      tmr      tmrAlarm
UpDown      upd      updDirection
Vertical scroll bar      vsb      vsbRate
Slider      sld      sldScale
Control type      Prefix      Example

ImageList      ils      ilsAllIcons
TreeView      tvw      treOrganization
Toolbar      tlb      tlbActions
TabStrip      tab      tabOptions
StatusBar      sta      staDateTime
ListView      lvw      lvwHeadings
ProgressBar      prg      prgLoadFile
RichTextBox      rtf      rtfReport
Bob LearnedCommented:
That goes back to the Hungarian Notation that Micro$oft is trying to get away from:)

xmlnewbieAuthor Commented:
TheLearnedOne, your link explains naming convention for everything else but does not specifically address controls. Did I overlook something?

Arthur_Wood, you went off on a tangent. Nevermind what I'll do if MS tells me to jump. I'll cross the bridge when I get there. For now, just make the assumption that all I want to know is what is MS's recommendation for naming controls. And no, I am not afraid of Bill Gates coming to my office to whip me with a limp noodle. I happen to have two in case of such situations. Bill Gates -- bring it on.
We already told you.  Hungarian notation is MS's recommendation.  They created it.  It's on their web site.  And it extends to controls.
"Prefix interface names with the letter I, to indicate that the type is an interface" - is this not hungarian notation? (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconinterfacenamingguidelines.asp)

Although not built by microsoft, it is build by a Microsoft Gold Certified Partner and distributed on MSDN as one of their best examples,
if you look at the TaskVision source code (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/wnf_TaskVision.asp) you will see that they use hungarian notation.
xmlnewbieAuthor Commented:
brianhj, I guess I am not making myself clear. I know Hungarian is MS's recommendation. I know the history of Hungarian notation. I know how to use it. I know it's on the MS web site. What I suppose I am not making clear is that MS DOES NOT RECOMMEND THE USE OF HUNGARIAN FOR VARIABLES, etc. in VB.NET. In other words, you will not find a variable named "strFirstName" in an application that follows MS's new convention.

rfgkev, are controls and interfaces the same? I've never prefixed a, say, text box with "I." Instead, I would use the prefix "tbx" (as in tbx_FirstName). Am I confused with the terminologies here? Is a text box (or form, or list box, or button) a control? I'll be looking at your link tomorrow.
They are being used in a different context, The interface was microsoft's recommendation for naming the actual interface class. With controls we are talking about naming instances of them in which case they are class level variables, and since microsoft recommend to not use hungarian notation for variables(although i have still not seen them say this anywhere so maybe you could post a link to somewhere you seen it) they must obviously not use hungarian notation for controls as they would be breaking their own recommendation.
"As it turns out, the Hungarian naming convention is quite useful—it's one technique among many that helps programmers produce better code faster. Since most of the headers and documentation Microsoft has published over the last 15 years have used Hungarian notation names for identifiers, many programmers outside of Microsoft have adopted one variation or another of this scheme for naming their identifiers."


This question is ridiculous.  Lol.
4th line down says "Reprinted November 1999"

The question relates to microsoft's recommendations for .NET
Yes I know it's from 1999.

It doesn't matter anyway.  He doesn't see that variable naming is personal preference.
And.. what difference does it make what version of the language you use?  Why would naming conventions for VB 4,5,6,.NET change?
yes, he was asking for Microsoft's recommendation on naming controls. Microsoft's recommendations on naming has changed quite a bit from VB6 to .Net, why? who knows.
xmlnewbieAuthor Commented:
The reason MS says to no longer use Hungarian is that the .NET IDE does a good job of helping you figure out what type a variable -- just place the mouse pointer over the variable in code editor and it'll show you how the variable was defined. If you are in debug mode, just look at the Locals and Watch windows and it'll tell you a variable's type.

brianhj, I realize naming convention is a personal preference. This is not a matter of personal preference. I am researching what MS's recommendation is. The link you posted does not apply to .NET.

rfgkev, take a look at this guide for naming properties in .NET: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconpropertynamingguidelines.asp - 3rd bullet say not to use Hungarian.
Bob LearnedCommented:
The truth is, no matter what Micro$oft or anybody else says, a programmer can do anything that they so choose.  You have the choice to do anything that you want.  

With VB.NET, C#, J#, and the other .NET programming languages, Micro$oft was trying to get away from type-specific variable names, since they violate cross-platform programming.  If you are not doing that, then I wouldn't worry:)

but the link  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconpropertynamingguidelines.asp relates to public properties, which nobody uses hungarian notation on anyway as it would just look silly.

The only things that say do not use hungarian are Public things, i.e properties/classes/namespaces etc... which a developer using your class would see. Nothing is said about Private variables.
as rfgkev points out:

"The following rules outline the naming guidelines for properties:"  

from the first line of the posted link. This advice says ABSOLUTELY NOTHING about naming conventuions for VARIABLES.  The advice to NOT USE HUNGARIAN notation applies to naming PROPERTIES of objects, where NO ONE, in his/her right mind, would ever even consider using Hungarian notation.  It would be sort of like advising you to NOT wear Combat Boots when swimming - or the advice that I have seen on some Irons - to NOT use them on clothes while the clothes are being worn.

The original question is asking about something that is irrelevant. Sorry to be so blunt.


This is all too much.
Yea theres a lot here, but basically, Microsoft doesn't want you to use str, int, or whatever anymore.. For example.. if in VB6 you had a variable named intCustomerID you might just use something like CustomerID or customerID in VB.NET. I myself still use all the same conventions used in VB6 because it's just what I'm used to. You should just find what style you like best and stick with it. Here are some sample styles for a counter variable:


It's all about choice and whatever YOU want to use.
xmlnewbieAuthor Commented:
Last time: I am trying to find out what Microsoft recommends. I realize I have the option to do whatever I want to. That's not the point. What is Microsoft's guidance on naming controls. I am specifically interested in the naming convention of controls only. I know for a fact that the MS has recommended against using Hungarian on "data type" variables (i.e. intCounter), classes (i.e. CHelloWorld), functions (i.e. intFoosball for a function that returns an integer), etc. Interfaces still seems to be prefixed with an "I" in VB.NET.

Please stop advising me that this issue is a personal preference. I am fully aware of that. However, I am really looking for MS's guidance on naming controls. And I need references.

I will request that this be deleted in a few days if I don't find the answer I am looking for.
You won't find the answer because there isn't one.
lol...it's very funny how sometimes a simple question (with a simple answer) gets soo complicated!

MS changed their naming convention because the IDE is so much better in providing a developer details about variables (types etc) that there is no longer a need to identify a variable type through it's prefix.

MS also recommend naming variables fully.  So if you need a variable to keep count of the number of wheels on a bus, use something like numberOfWheelsOnBus rather than intWheelCounter.

Everything (to my understanding) in .NET is an object.  Yes, they have value objects and reference objects (read up on this because I'm not gonna explain it) but everything is an object (feel free to correct me if I'm wrong here) including controls.

So, when it comes to controls, MS are suggesting you use the same naming convention.

So where in VB you would have previously called a textbox containing a firstname something like "txtFirstName" you should now call it firstNameTextBox.

This is my interpretation of the MS naming guidelines...but thats what a naming convention is there for...interpretation.

I think it's good that everyone adopts the same standard but it's never gonna happen...so just code how you're comfortable  :)


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.