Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Loops

  • 19-11-2002 09:06AM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 2,277 ✭✭✭DiscoStu


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

    the infinite loop


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 446 ✭✭kegan5


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


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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,563 ✭✭✭Typedef


    Umm why don't you just make your integer static


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


    umm why not indeed...


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


    .


  • Registered Users, Registered Users 2 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