Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Naming conventions 1

Status
Not open for further replies.

johnisotank

Technical User
Aug 8, 2008
258
GB
Hi all.

just a quick one. I am looking at improving the naming conventions used in my code and just wondered what people do here.

Obviously if the control is a text box I should call it txtMyTextBox.

If I drag 20 fields from my database onto a form it automatically assigns names such as JobNumberTextBox, EmployeeTextBox.

Would you recommend I stop being lazy and rename all these to txtJobNumber, txtEmployee?

Thanks
John
 
I have seen in various training materials it done either way. It usually is what is more comfortable to you and if you develop with a team, to stay uniform.
 
Stop being lazy. There is nothing more irritating than multiple naming schemes in the same code. Pick a schema and stay with it. It'll help your co-workers and anyone who has to follow you to make adjustments.

--------------------------------------------------
Bluto: What? Over? Did you say "over"? Nothing is over until we decide it is! Was it over when the Germans bombed Pearl Harbor? No!
Otter: Germans?
Boon: Forget it, he's rolling.
--------------------------------------------------
 
Hi, thanks for the replies.

I will stop being lazy then! :)

I dont know what schema will have been followed by someone taking up my code but if I stick to the ones recommended on the microsoft websites then at least I have made an effort to put it in a recognizable format.

Cheers
John
 

Don't forget about naming your variables the same way, by your naming conventions. For example:
[tt]
Dim [red]str[/red]LastName As String
Dim [red]int[/red]Count As Integer
etc.
[/tt]
or whatever way you choose, just name them all the same way. Be consistent.

Have fun.

---- Andy
 
Here's a good article on Hungarian notation (towards the bottom):

I don't ever prefix my value type variables with their type. I've adopted the naming convention mentioned in the article.

As to the original question, I personally would rename the text box variables to begin with "txt". If you do a lot of this, you may want to investigate writing a macro which does a find and replace using regular expressions to change all FieldNameTextBox to txtFieldName.
 
gonna have to agree with Dave here. Not really needed on the variables, but the controls absolutely.... it makes it easier on the intellisence to. Remember, FieldNameLable comes before FieldNameTextbox.

--------------------------------------------------
Bluto: What? Over? Did you say "over"? Nothing is over until we decide it is! Was it over when the Germans bombed Pearl Harbor? No!
Otter: Germans?
Boon: Forget it, he's rolling.
--------------------------------------------------
 
Out of my own curiosity I created the following macro to rename all automatically named database text boxes like I described above. The Macro Explorer window may be reached by pressing Alt+F8.

Code:
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module CodingStandards

    Sub StandardizeTextBoxNames()

        With DTE.Find
            .Action = vsFindAction.vsFindActionReplaceAll
            .FindWhat = "<{:i}TextBox>"
            .ReplaceWith = "txt\1"
            .Target = vsFindTarget.vsFindTargetSolution
            .MatchCase = True
            .MatchWholeWord = False
            .MatchInHiddenText = False
            .PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
            .KeepModifiedDocumentsOpen = False
            .FilesOfType = ""
            .ResultsLocation = vsFindResultsLocation.vsFindResults1
            .Action = vsFindAction.vsFindActionReplaceAll
            If (.Execute = vsFindResult.vsFindResultNotFound) Then
                Throw New System.Exception("No *TextBox variables found")
            End If
        End With

    End Sub

End Module
 
Now for the 64k dollar question.

Does anyone know how to change the default naming in vs.net so when you drag an object such as a textbox to a form it's name begins with tbx instead of ending with TextBox?
 
I don't know how, but I'm not sure that would save you much. If you ended up with "txt1", "txt2", "txt3", etc., you are still going to have to change the name for something meaningful.
 
OMG, RiverGuy just said "I don't know how" You're my Idol, I though you knew everything :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top