Reputation: 673
Incrementing the value of a variable by one is often achieved in other basic dialects in ways like
myreallylongandawkwardvariable ++
or
inc(myreallylongandawkwardvariable)
Is the only way to achieve this in VBA to code like this?
myreallylongandawkwardvariable = myreallylongandawkwardvariable +1
Upvotes: 0
Views: 12950
Reputation: 1
@DanBaeckström, that is Not strictly correct. If you call a procedure simply by its name, as in: Increment myreallylongandawkwardvariable you don't use parentheses. But, if you precede this procedure call with the keyword "Call", as in: Call Increment(myreallylongandawkwardvariable) you MUST use parentheses.
Upvotes: 0
Reputation: 7880
That is the only standard way to increment a variable with VBA.
If you really want to, you can create a custom procedure:
Sub Increment(ByRef var, Optional amount = 1)
var = var + amount
End Sub
Then you can do the following:
Increment myreallylongandawkwardvariable 'Increment by 1
Increment myreallylongandawkwardvariable, 5 'Increment by 5
Upvotes: 3