Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Loops

Options
  • 19-11-2002 10:06am
    #1
    Registered Users Posts: 446 ✭✭


    is it possible to use a + command without using a loop?

    Im looking for code that adds 1 to a number when someone clicks on the confirm button..however the only way I can get it to work is by using a do while loop and although this works it has to have a condition so I cant keep the loop running for the whole program it just keeps going around the loop 10 times because of the condition?
    Any ideas
    Thanks


Comments

  • Registered Users Posts: 2,277 ✭✭✭DiscoStu


    c++ i assume
    int loop_condition = 0
    
    while(loop_condition == 0)
    {
      blah blah blah....
    }
    

    the infinite loop


  • Registered Users Posts: 2,660 ✭✭✭Baz_


    em, language and what you are trying to do would be nice....

    Sounds like you just want to add 1 to a variable every time someone clicks on a button, if thats the case what you want is to write a function to do it, however I could be wrong because you confused me with talk of loops, and whiles.


  • Registered Users Posts: 446 ✭✭kegan5


    Sorry its VB but would that work in Vb...? I'll try it thanks


  • Registered Users Posts: 2,660 ✭✭✭Baz_


    if you are just incrementing a variable by 1 every time the command button is clicked, then yes all you need to do is have a sub for the button clicked event to do it.


  • Registered Users Posts: 446 ✭✭kegan5


    Private Sub cmdConfirm_Click()
    Dim intX As Integer
    intX = 0

    MsgBox "The number if people enrolled on this course is " & intX
    intX 1



    End Sub


    Thats the code I was using, as you can see theres no + and it just automatically deletes it when I put it in and it says :
    "Expected Sub, Function " ?


  • Advertisement
  • Registered Users Posts: 2,660 ✭✭✭Baz_


    Originally posted by kegan5
    Private Sub cmdConfirm_Click()
    Dim intX As Integer
    intX = 0

    MsgBox "The number if people enrolled on this course is " & intX
    intX 1



    End Sub


    Thats the code I was using, as you can see theres no + and it just automatically deletes it when I put it in and it says :
    "Expected Sub, Function " ?

    'Make this global. If it is local it gets reset every time you enter the Sub
    Dim intX As Integer

    Private Sub Form_Load()
    'initialise in the forms load event
    intX=0
    End Sub

    Private Sub cmdConfirm_Click()
    'Add 1 to intX, and print message
    intX = intX + 1
    MsgBox "The number if people enrolled on this course is " & intX

    End Sub


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    Umm why don't you just make your integer static


  • Registered Users Posts: 2,660 ✭✭✭Baz_


    umm why not indeed...


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    .


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Evil Phil
    When the variable is declared in a sub as you have done it will remain in memory only as the sub is executing. Once the end sub is executed all the variables are dropped (for want of a better word).

    Except, as Type pointed out, the ones defined as static.

    Cause thats exactly what static variables are for...

    jc


  • Advertisement
Advertisement