Naming Visual Basic Variables - Guidelines to Follow for VB Programming
Naming Visual Basic Variables - Guidelines to Follow for VB Programming
If you're writing a program in Visual Basic for Applications (VBA) or Visual Basic (VB), you should take care to use good variable names. The author has been programming now for more than 20 years, and has come to realise that giving variables sensible names is vital if you're to write good code. This artcile gives some guidelines to help you!
Names to Avoid
Let's start off with some naming conventions to avoid. The first one is to use single-character or short names. For example:
DIM s AS String
Althought this undoubtedly saves time, it makes code difficult to understand. For example, if you see this at the top of a program, your heart would sink:
DIM s1 AS String, s2 AS String
DIM s3 AS String
Do yourself a favour - use longer names!
Use Camel Case
Camel case is the term used to describe variable names which use capital letters to begin each new word, while not using spaces. Here are some examples of camel case variable names:
DIM InterestRate AS Single
DIM VatRate AS Double
DIM UserName AS String
Notice how in each case the use of multiple words with capital letters for each makes the variable name easier to understand and read.
Don't Specify Variable Type
Many technical people will advise you to use 3 letters to prefix each variable, to denote what sort of data type it is. Thus the 3 variables above should read:
DIM sngInterestRate AS Single
DIM dblVatRate AS Double
DIM strUserName AS String
Some people consider this improves programming - we just thinks it makes your code look cluttered, and harder to understand.
Don't be Afraid of Long Names
If you've got a variable which will hold the name of an Excel workbook used to hold interest rate assumptions, don't be afraid to call it ExcelnterestRateWorkbook. Long variable names make code easier to understand!
Why the Classic Porsche 911 is so Special RESPA basics: What you should be aware of Use Of Biomarkers Becoming More Widespread 5 Ways Accountants Use Gotomeeting Anabolic steroids for the bones Things To Do In Andorra La Vella What To consider Selecting a Sofa Bed All About Pewter Flasks How To Achieve More By Starting With What You Have Throwing Out A Bad Ego Everything That You Wanted To Know About Waterjet Cutting You can refurbish your floors with the epoxy floor coatings Spiritual Growth With The Tarot - 13, DEATH
www.yloan.com
guest:
register
|
login
|
search
IP(216.73.216.142) California / Anaheim
Processed in 0.016583 second(s), 5 queries
,
Gzip enabled
, discuz 5.5 through PHP 8.3.9 ,
debug code: 44 , 2069, 85,
Naming Visual Basic Variables - Guidelines to Follow for VB Programming Anaheim