Question

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?

Was it helpful?

Solution

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

OTHER TIPS

Hungarian is better used to reflect the meaning of a variable than its type. For example, if you have a bunch of weights in your program, rather than having dblWeightGold, dblWeightSilver, etc. just cite them as wgtGold, wgtSilver.

In a type-checked world it's not so important to state the fundamental type in the variable name. I no longer sign my variables this way and I do work in VBA.

I will, however, vote up GuinnessFan. It's your convention. As long as it's consistent and makes sense, it'll be fine. There is no one true convention.

I always preface with intVar2, intVar3, or lngVar4, txtMyTextBox, lblMyLabel etc...

intVar1
intVar2
lngVar1
txtMyTextbox
lblMyLabel
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top