tags:

views:

130

answers:

3

This is probably a trivial question, but I'm curious as to what other Excel VBA programmers think.

When I program excel 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's easier to just make everything a long than it is to figure out if it is ever possible for the value of variable to exceed 32768.

Is it okay to denote these variables with a leading i instead of l, since I'm using them as integers?

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's holding a long.

dim nObjects as long, nPlots as long

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

+2  A: 

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

intVar1
intVar2
lngVar1
txtMyTextbox
lblMyLabel
Climber104
+4  A: 

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

Jeff O
+2  A: 

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.

Joel Goodwin