excelcoding-stylenaming-conventionshungarian-notationvba

Excel-VBA: Variable Names, Hungarian Notation and Variable Naming Best Practices


When I program in Excel-VBA I use Hungarian notation. Worksheet variables start with ws, workbook variables start wb, etc.

When I use integers, I always use longs, because in the past I have exceeded the maximum value of an integer, and it takes a while to find the bug - it is easier to just make everything a long, rather than trying to figure out if it is ever possible for the value of a variable to exceed 32768.

Is it okay to denote these variables with a leading i instead of l, since I am using them as integers, i.e.:

dim iStart as long, iEnd as long

instead of

dim lStart as long, lEnd as long

When a variable holds the quantity of something, I denote it with an n, even though it is holding a long.

dim nObjects as long, nPlots as long

What is your experience as to which notation makes VBA easiest to read?


Solution

  • Not really. Be consistent. Document. Consider your fellow developers if your team grows.