LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default A "+=" Operator like in C?

i+=1 instead of i=i+1

Just to mention if you like it.
When we just want to increase a variable by 1, we most likely would use
the PreIncrement function "++" (ie ++ v)

In vba, it's generally not recommended, but we can have fun with
function names in a few cases.
I also have the Inc function, but whose name is ++, or the characters
Alt + 0134 (twice)
Hold down the Alt key and type 0134.

Function ††(ByRef n) ' Alt + 0134
n = n + 1
End Function


Sub Demo()
Dim n
n = 5
†† n
End Sub

'n is now 6.

You have to use a little imagination to find characters that are close
to what you need. In addition, not all characters are valid.

HTH
Dana DeLouis



Dana DeLouis wrote:
Does anyone know if there is a VBA-equivalent
of the "+=" operator in C.

i+=1 instead of i=i+1


Here' a workaround that I use for the Increment function.
I also have a "Decrement" function as well.

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

Sub Demo()
Dim AVeryLongVariableName
AVeryLongVariableName = 5

AVeryLongVariableName = AVeryLongVariableName + 1
'or
Inc AVeryLongVariableName
End Sub

HTH
Dana DeLouis


Charles wrote:
That basically answers my question. I must say I have never been a
great fan of C/C++ (too rigorous for me) but I regret a few functions
like that one...

thanks!
Charles

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text "comparison" operator for "contains" used in an "IF" Function Pawaso Excel Worksheet Functions 4 April 4th 23 11:35 AM
Is it possible to apply IF's to "operator" result.. nastech Excel Discussion (Misc queries) 3 August 11th 06 02:12 PM
program stuck at "Save Cancelled by Operator" MainelyPat Excel Discussion (Misc queries) 3 April 20th 06 06:23 PM
How 2 use right shift "<<" and left shift "" operator in excel? v-2ajpau Excel Programming 2 December 28th 05 01:33 PM
Excel no longer allows new formulas with division "/" operator SA Excel Programming 1 November 1st 03 07:07 AM


All times are GMT +1. The time now is 04:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"