This is gonna stupid but is there and Increment function in VB? that will inc any integer var by another integer or just 1.
thanx
Printable View
This is gonna stupid but is there and Increment function in VB? that will inc any integer var by another integer or just 1.
thanx
Well, you can always do this:
X = X + 1
This will increment the variable X by one.
X = X + Y
This will increment the variable X by Y.
You can always use other mathematical expressions:
X = X - 1
X = X / 2
X = X * Y + 5
X = Cos(X * Sin(5 ^ Y)) :rolleyes:
Don't know of any functions for that. Like ++ in C. But we are currently working on a new reference library DLL, and inc happens to be one of the functions we have built. If there are any others you would like to see let us know.
[email protected] or [email protected].
I have known about that incrementing for a long time...
I always try to use it, like in a timer, and it never works....
I set the timer interval to 1000, I enable the timer
and put this code into the timer1_timer module
this doesnt work... text1 = 1 then it doesnt do anything elseCode:Private Sub Timer1_Timer()
i = i + 1
Text1 = i
End Sub
If you really want to use a function:
Sub Inc(ByRef X, Optional ByVal NumberToIncreaseBy = 1)
X = X + NumberToIncreaseBy
End Sub
Same with Dec except a minus instead of a plus.
Regarding the timer...
Whenever the timer routine is called, the I variable is recreated and reset with zero. To make it static (not reset), you have to tell it to be static, like this:
Code:Private Sub Timer1_Timer()
Static I As Integer
I = I + 1
Text1 = I
End Sub
Or you could decalre a variable as Public or Global in a module, then in a Timer, put the following code.
Code:Private Sub Timer1_Timer()
' Add 1 to the variable
MyVar = MyVar + 1
Text1 = MyVar
End Sub