increment operator?

P

Peter Morris

Is there a shorthand increment operator ?

eg something like :
Inc(long.variable.name)

which would be easier to read than
long.variable.name = long.variable.name + 1



Also decrement too.
 
J

Jim Cone

You could create one...
lngNum = AddOne(lngNum)

Function AddOne(ByVal lngN As Long) As Long
AddOne = lngN + 1
End Function

-or-

Call AddOne(lngNum)

Function AddOne(ByRef lngN As Long)
lngN = lngN + 1
End Function
-----------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Peter Morris"
<nospam.ple@se>
wrote in message
Is there a shorthand increment operator ?
eg something like :
Inc(long.variable.name)

which would be easier to read than
long.variable.name = long.variable.name + 1
Also decrement too.
 
D

Dana DeLouis

eg something like :
Inc(long.variable.name)

Excel vba doesn't have the ++n operator as in some other programs.
Another option similar to Jim's but without parenthesis might be:

Function Inc(ByRef n)
'// Increment by +1
n = n + 1
End Function

Sub Example()
Dim long_variable_name
long_variable_name = 10

Inc long_variable_name
End Sub
 
Top