[mso] Re: VBA Naming Convention User Preference
- From: "Dian Chapman" <dian@xxxxxxxxxxxxx>
- To: <mso@xxxxxxxxxxxxx>
- Date: Wed, 12 Nov 2008 22:38:10 -0600
True...naming conventions are MOSTLY for your own sanity. However, that idea
goes out the window if you'll have to share your code with someone else in
the future.
If you're the only one who would ever read the code, calling a string a
potato might make sense to you<g>...but make sure you ALWAYS call it a
potato and hope no one ever has to read your code.
Personally...I generally use strMyVar for strings and gstrMyVar for globals.
I don't get too much more specific to procedure or local...since I always
use new/logical vars.
To each his/her own. But yes, there's a lot of info on the web and if you
stick with fairly universal standards...others who might have to read your
code in the future won't think you're a nutjob or want to kill you when they
can't figure your stuff out! ;-)
Dian D. Chapman
Technical Consultant, Microsoft MVP
MOS Certified Instructor, Editor/TechTrax Ezine
Tech Editor for Word & Office 2007 Bibles
https://mvp.support.microsoft.com/profile/Dian.Chapman
Soldiers' Angels Blankets of Belief
http://www.mousetrax.com/dian/angels.html
Free Computer Tutorials: http://www.techtrax.us
Free Word Tricks eBook: http://www.mousetrax.com/books.html
Learn VBA the easy way: http://www.mousetrax.com/techcourses.html
-----Original Message-----
From: mso-bounce@xxxxxxxxxxxxx [mailto:mso-bounce@xxxxxxxxxxxxx] On Behalf
Of Green
Sent: Wednesday, November 12, 2008 2:05 PM
To: mso@xxxxxxxxxxxxx
Subject: [mso] Re: VBA Naming Convention User Preference
I like to know where the variable is coming from so I use..
l = Local to that subroutine.
g = Global.. I put all my globals in a seperate module.
p = A parameter of the function/subroutine.
i = integer.
s = string.
slVariable would be a string variable defined locally.
ipVaraible would be an integer defined in the parameters of the call.
... And so on.
I used to use stuff lik glb and int and str and so on but got lazy :-)
As Bear says though... There aint no hard and fast rules. If it works for
you then that's the way to go... But it is a good idea to look at the whys
and wherefores of people who've been at it some time.
Those are good links from Bear and well worth checking out.
There is a *lot* of stuff out there about variables and naming conventions.
HTH
Lisa
> Hi Lisa
> I notice that to name your variables you use eg rlCell as
> Range which i make out to be "r" for range what's the "l" for
> and there others you normally adopt as some sort of naming
> convention and more importantly why!. Maybe Linda could run
> an enquiry to see what sort of conventions users are using.
> I use as below, hope the table comes out properly.
> Rgds
> KZ
> VBA Naming Convention
>
>
> Object
>
> Convention
>
> preferred
>
> example
>
> Integer
>
> % or i or c or int
>
> %
>
> integer% or intIntegerName
>
> long
>
> &or l or c or lng
>
> &
>
> long& or lngLongName
>
> single
>
> ! or s or sng
>
> !
>
> single! or sngSingleName
>
> double
>
> # or d or dbl
>
> #
>
> double# or dblDoubleName
>
> currency
>
> @ or cur
>
> @
>
> currency@ or curCurrencyName
>
> string
>
> $ or s or str
>
> $
>
> string$ or strStringName
>
>
>
>
>
>
>
>
>
> variant
>
> v or var
>
> var
>
> varVariant
>
> date
>
> dt
>
> dt
>
> dtDate
>
> boolean
>
> b or f
>
> bln
>
> blnBoolen
>
> byte
>
> b or bt
>
> byt
>
> bytByte
>
> user defined type
>
> u or ut
>
> udt
>
> udtUserDefinedType
>
>
>
>
>
>
>
>
>
> range
>
> rng
>
> rng
>
> rngRange
>
> workbook
>
> wb or wbk
>
> wbk
>
> wbkWorkbook
>
>
>
>
>
>
>
>
>
> worksheet
>
> ws or wks
>
> wks
>
> wksWorksheet
>
> chart
>
> ch or chrt
>
> chrt
>
> chrtChart
>
> pivot table
>
> pt or pvt
>
> pvt
>
> pvtPivotTable
>
> font
>
> fnt
>
> fnt
>
> fntFont
>
>
>
>
>
>
>
>
>
> global variable
>
> g or glb
>
> glb
>
> glbGlobalName
>
>
>
>
>
>
>
>
>
> constant variable
>
> CONSTANT
>
> All Caps
>
> CONSTANTNAME
*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or
MicrosoftOffice@xxxxxxxxxxxxxxxx
To send mail to the group, simply address it to mso@xxxxxxxxxxxxx
To Unsubscribe from this group, visit the group's homepage and use the
dropdown menu at the top. This will allow you to unsubscribe your email
address or change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso
To be able to share files with the group, you must join our Yahoo sister
group. This group will not allow for posting of emails, but will allow you
to join and share problem files, templates, etc.:
http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for FILE
SHARING ONLY.
If you are using Outlook and you see a lot of unnecessary code in your email
messages, read these instructions that explain why and how to fix it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************
*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or
MicrosoftOffice@xxxxxxxxxxxxxxxx
To send mail to the group, simply address it to mso@xxxxxxxxxxxxx
To Unsubscribe from this group, visit the group's homepage and use the dropdown
menu at the top. This will allow you to unsubscribe your email address or
change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso
To be able to share files with the group, you must join our Yahoo sister group.
This group will not allow for posting of emails, but will allow you to join
and share problem files, templates, etc.:
http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for FILE
SHARING ONLY.
If you are using Outlook and you see a lot of unnecessary code in your email
messages, read these instructions that explain why and how to fix it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************
Other related posts: