Visual Basic 6 Naming Standards

    技术2022-05-11  154

    This contains the Microsoft Recommended naming conventions for Objects, and Variables in Visual Basic 6.0.

     

    Why is this here? I believe it is always important to follow some standard when coding, and if your job involves VB programming, then I'm sure you will agree that it definitely makes code easier to read and understand.  Most if not all, IT jobs will require you to follow a set of standards while writing your code. 

    The Visual Basic Coding standards have changed over the years but they are still about the same, with the Scope and Type identifiers to tell if a variable is global, module or local, and what the data type of the variable is.  I remember the previous set of standards used only a single character type identifier. (most of the code in this site still uses the old standard, I just have not caught on to the new one yet.) The new standard of the 3 character type identifier makes VB's standards more like that of Visual C++. (I doubt this is coincidence.)

       

    Visual Basic Naming Standards
    Control typeprefixExample
    3D PanelpnlpnlGroup
    ADO DataadoadoBiblio
    Animated buttonanianiMailBox
    Check boxchkchkReadOnly
    Combo box, drop-down list boxcbocboEnglish
    Command buttoncmdcmdExit
    Common dialog dlgdlgFileOpen
    Communications comcomFax
    Control (used within procedures when the specific type is unknown)ctrctrCurrent
    DatadatdatBiblio
    Data-bound combo boxdbcbodbcboLanguage
    Data-bound griddbgrddbgrdQueryResult
    Data-bound list boxdblstdblstJobType
    Data combodbcdbcAuthor
    Data griddgddgdTitles
    Data listdbldblPublisher
    Data repeaterdrpdrpLocation
    Date pickerdtpdtpPublished
    Directory list boxdirdirSource
    Drive list boxdrvdrvTarget
    File list boxfilfilSource
    Flat scroll barfsbfsbMove
    FormfrmfrmEntry
    FramefrafraLanguage
    GaugegaugauStatus
    GraphgragraRevenue
    GridgrdgrdPrices
    Hierarchical flexgridflexflexOrders
    Horizontal scroll barhsbhsbVolume
    ImageimgimgIcon
    Image comboimgcboimgcboProduct
    ImageListilsilsAllIcons
    LabellbllblHelpMessage
    Lightweight check boxlwchklwchkArchive
    Lightweight combo boxlwcbolwcboGerman
    Lightweight command buttonlwcmdlwcmdRemove
    Lightweight framelwfralwfraSaveOptions
    Lightweight horizontal scroll barlwhsblwhsbVolume
    Lightweight list boxlwlstlwlstCostCenters
    Lightweight option buttonlwoptlwoptIncomeLevel
    Lightweight text boxlwtxtlwoptStreet
    Lightweight vertical scroll barlwvsblwvsbYear
    LinelinlinVertical
    List boxlstlstPolicyCodes
    ListViewlvwlvwHeadings
    MAPI messagempmmpmSentMessage
    MAPI sessionmpsmpsSession
    MCImcimciVideo
    MenumnumnuFileOpen
    Month viewmvwmvwPeriod
    MS ChartchchSalesbyRegion
    MS Flex gridmsgmsgClients
    MS Tab mstmstFirst
    OLE containeroleoleWorksheet
    Option buttonoptoptGender
    Picture boxpicpicVGA
    Picture clipclpclpToolbar
    ProgressBarprgprgLoadFile
    Remote DatardrdTitles
    RichTextBoxrtfrtfReport
    ShapeshpshpCircle
    SlidersldsldScale
    SpinspnspnPages
    StatusBarstastaDateTime
    SysInfosyssysMonitor
    TabStriptabtabOptions
    Text boxtxttxtLastName
    TimertmrtmrAlarm
    ToolbartlbtlbActions
    TreeViewtretreOrganization
    UpDownupdupdDirection
    Vertical scroll barvsbvsbRate

     

     

    Variable Naming Conventions

    Visual Basic uses a Scope and Type identifier to prefix each variable name, so it is easy to tell the data type of the variable and where the variable is declared. The Scope can be one of three things:

    ScopePrefixExample
    GlobalggstrUserName
    Module-levelmmblnCalcInProgress
    Local to procedureNonedblVelocity

    The Type identifier follows the Scope identifier and will enable anyone looking at your code to instantly know the data type of all your variables without having to look for the variables declaration. The following is a list of the data types and their prefixes:

    Data typePrefixExample
    BooleanblnblnFound
    BytebytbytRasterData
    Collection objectcolcolWidgets
    CurrencycurcurRevenue
    Date (Time)dtmdtmStart
    DoubledbldblTolerance
    ErrorerrerrOrderNum
    IntegerintintQuantity
    LonglnglngDistance
    ObjectobjobjCurrent
    SinglesngsngAverage
    StringstrstrFName
    User-defined typeudtudtEmployee
    VariantvntvntCheckSum

    So if you had a global variable named "Counter" and it is a long, you would name the variable "glngCounter" Anyone looking at this variable would instantly know the variable is global to the whole project and would know it is a long. In a multi-developer environment this type of standard is a must, or else there will be considerable time lost while each developer keeps referring to the variable declarations.


    最新回复(0)