incrementing integers - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

incrementing integers

ryanc2k3ryanc2k3 Posts: 28Member
[b][red]This message was edited by ryanc2k3 at 2004-1-29 7:3:29[/red][/b][hr]
im making an application that has a customer number field, and i want my number field to automatically increment when i press the command button, im more familiar in the ++ operator used in c/c++, is there any command in vb that is similar with the ++ operator in c/c++? because when im going to use the do loop it results to infinite loop, and when im going to place the formula "counter=1+counter" it doesnt have any effect...


Comments

  • JonathanJonathan Posts: 2,914Member
    : [b][red]This message was edited by ryanc2k3 at 2004-1-29 7:3:29[/red][/b][hr]
    : im making an application that has a customer number field, and i want my number field to automatically increment when i press the command button, im more familiar in the ++ operator used in c/c++, is there any command in vb that is similar with the ++ operator in c/c++? because when im going to use the do loop it results to infinite loop, and when im going to place the formula "counter=1+counter" it doesnt have any effect...
    :
    Post to top bit of your do loop, but I think your code simply isn't doing what you expect.

    While counter = 1 + counter

    In VB is equivalent to the C:-

    while (counter == 1 + counter)

    Of course, a number will never be equal to 1 plus itself. You'll have to do the incrementation in the loop body.

    And thus another example of why using the same operator for equality and assignment is a bad idea...

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • PavlinIIPavlinII Posts: 404Member
    : [b][red]This message was edited by ryanc2k3 at 2004-1-29 7:3:29[/red][/b][hr]
    : im making an application that has a customer number field, and i want my number field to automatically increment when i press the command button, im more familiar in the ++ operator used in c/c++, is there any command in vb that is similar with the ++ operator in c/c++? because when im going to use the do loop it results to infinite loop, and when im going to place the formula "counter=1+counter" it doesnt have any effect...
    :
    :
    :
    Hi, what exactly do you want? You have a button and you want "counter" to be increment when button is pressed? Does counter = counter + 1 returns 1 everytime? ;) You have to declare counter outside the procedure (Public or Private) or like Static (if it's declared inside the button procedure).. And what was the problem with do - loop? Without condtition it makes infinite loops...

    PavlinII
  • ryanc2k3ryanc2k3 Posts: 28Member
    : : [b][red]This message was edited by ryanc2k3 at 2004-1-29 7:3:29[/red][/b][hr]
    : : im making an application that has a customer number field, and i want my number field to automatically increment when i press the command button, im more familiar in the ++ operator used in c/c++, is there any command in vb that is similar with the ++ operator in c/c++? because when im going to use the do loop it results to infinite loop, and when im going to place the formula "counter=1+counter" it doesnt have any effect...
    : :
    : :
    : :
    : Hi, what exactly do you want? You have a button and you want "counter" to be increment when button is pressed? Does counter = counter + 1 returns 1 everytime? ;) You have to declare counter outside the procedure (Public or Private) or like Static (if it's declared inside the button procedure).. And what was the problem with do - loop? Without condtition it makes infinite loops...
    :
    : PavlinII
    :
    yes thats exactly my problem, im used in using c++ wherein i dont have to declare a do-loop to increment a number, example i have an integer A, in c i would declare A++ to increment this integer, so everytime i add a new record int A would increment by 1, this way i can add records one at time, because adding all records at one time would make the program less reliable. And in C it wont create an infinite loop. im looking for an equivalent declaration for this in vb6
  • PavlinIIPavlinII Posts: 404Member
    : : : [b][red]This message was edited by ryanc2k3 at 2004-1-29 7:3:29[/red][/b][hr]
    : : : im making an application that has a customer number field, and i want my number field to automatically increment when i press the command button, im more familiar in the ++ operator used in c/c++, is there any command in vb that is similar with the ++ operator in c/c++? because when im going to use the do loop it results to infinite loop, and when im going to place the formula "counter=1+counter" it doesnt have any effect...
    : : :
    : : :
    : : :
    : : Hi, what exactly do you want? You have a button and you want "counter" to be increment when button is pressed? Does counter = counter + 1 returns 1 everytime? ;) You have to declare counter outside the procedure (Public or Private) or like Static (if it's declared inside the button procedure).. And what was the problem with do - loop? Without condtition it makes infinite loops...
    : :
    : : PavlinII
    : :
    : yes thats exactly my problem, im used in using c++ wherein i dont have to declare a do-loop to increment a number, example i have an integer A, in c i would declare A++ to increment this integer, so everytime i add a new record int A would increment by 1, this way i can add records one at time, because adding all records at one time would make the program less reliable. And in C it wont create an infinite loop. im looking for an equivalent declaration for this in vb6
    :
    Hi, here are some examples:
    (After declaring has integer variable zero value. int Counter=0; is not needed)
    [code][green]'Counter will start at zero everytime you call this sub[/green]
    Sub DoLoopSub()
    Dim Counter As Integer
    Do While Counter < 10
    Counter = Counter + 1
    MsgBox Counter
    ...blablabla...
    Loop
    End Sub

    [green]'Counter will keep it's value to next calling
    'When you call this sub second time, Counter will be 10[/green]
    Sub DoLoopSub()
    Static Counter As Integer
    If YouWantToSetCounterToZero Then Conter = 0
    Do While Counter < 10
    Counter = Counter + 1
    MsgBox Counter
    ...blablabla...
    Loop
    End Sub

    [green]'Like the previous one, but Counter will be readable from others subs[/green]
    Private Counter As Integer
    [green]'Pulic Counter As Integer 'If used in module and you want to read it from another modules, forms...[/green]

    Sub DoLoopSub
    If YouWantToSetCounterToZero Then Conter = 0
    Do While Counter < 10
    Counter = Counter + 1
    MsgBox Counter
    ...blablabla...
    Loop
    End Sub

    [green]'Some another Do - Loop cycle:[/green]
    Do
    Counter = Counter + 1
    MsgBox Counter
    ...blablabla...
    Loop Until Counter > 9
    [green]'The different is clear - this one will run inside Do-Loop at least once time ;))[/green][/code]Hope it's enough, you'll find there what you'll need ;))

    PavlinII
  • ryanc2k3ryanc2k3 Posts: 28Member
    : : : : [b][red]This message was edited by ryanc2k3 at 2004-1-29 7:3:29[/red][/b][hr]
    : : : : im making an application that has a customer number field, and i want my number field to automatically increment when i press the command button, im more familiar in the ++ operator used in c/c++, is there any command in vb that is similar with the ++ operator in c/c++? because when im going to use the do loop it results to infinite loop, and when im going to place the formula "counter=1+counter" it doesnt have any effect...
    : : : :
    : : : :
    : : : :
    : : : Hi, what exactly do you want? You have a button and you want "counter" to be increment when button is pressed? Does counter = counter + 1 returns 1 everytime? ;) You have to declare counter outside the procedure (Public or Private) or like Static (if it's declared inside the button procedure).. And what was the problem with do - loop? Without condtition it makes infinite loops...
    : : :
    : : : PavlinII
    : : :
    : : yes thats exactly my problem, im used in using c++ wherein i dont have to declare a do-loop to increment a number, example i have an integer A, in c i would declare A++ to increment this integer, so everytime i add a new record int A would increment by 1, this way i can add records one at time, because adding all records at one time would make the program less reliable. And in C it wont create an infinite loop. im looking for an equivalent declaration for this in vb6
    : :
    : Hi, here are some examples:
    : (After declaring has integer variable zero value. int Counter=0; is not needed)
    : [code][green]'Counter will start at zero everytime you call this sub[/green]
    : Sub DoLoopSub()
    : Dim Counter As Integer
    : Do While Counter < 10
    : Counter = Counter + 1
    : MsgBox Counter
    : ...blablabla...
    : Loop
    : End Sub
    :
    : [green]'Counter will keep it's value to next calling
    : 'When you call this sub second time, Counter will be 10[/green]
    : Sub DoLoopSub()
    : Static Counter As Integer
    : If YouWantToSetCounterToZero Then Conter = 0
    : Do While Counter < 10
    : Counter = Counter + 1
    : MsgBox Counter
    : ...blablabla...
    : Loop
    : End Sub
    :
    : [green]'Like the previous one, but Counter will be readable from others subs[/green]
    : Private Counter As Integer
    : [green]'Pulic Counter As Integer 'If used in module and you want to read it from another modules, forms...[/green]
    :
    : Sub DoLoopSub
    : If YouWantToSetCounterToZero Then Conter = 0
    : Do While Counter < 10
    : Counter = Counter + 1
    : MsgBox Counter
    : ...blablabla...
    : Loop
    : End Sub
    :
    : [green]'Some another Do - Loop cycle:[/green]
    : Do
    : Counter = Counter + 1
    : MsgBox Counter
    : ...blablabla...
    : Loop Until Counter > 9
    : [green]'The different is clear - this one will run inside Do-Loop at least once time ;))[/green][/code]Hope it's enough, you'll find there what you'll need ;))
    :
    : PavlinII
    :
    ok thanks for the example! ill try to add them to my code and see if it would function. thanks for your help!
Sign In or Register to comment.