Results 1 to 6 of 6

Thread: increment

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    1
    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

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    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))

  3. #3
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655

    Cool

    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].

  4. #4
    Guest
    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

    Code:
    Private Sub Timer1_Timer()
    i = i + 1
    Text1 = i
    End Sub
    this doesnt work... text1 = 1 then it doesnt do anything else

  5. #5
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    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

  6. #6
    Guest
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width