Results 1 to 6 of 6

Thread: Looping

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    Colorado
    Posts
    23
    I am new to VB and am trying to build a simple loop to add numbers from two text boxes and display the result in a label. For instance, if the user inputs 1 and 5 into two text boxes and then clicks on the sum command button, the code will add 1+2+3+4+5 and display the result in the result label. Can anyone help me with the code?

  2. #2
    Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    52
    Is this what your after?

    text3 = ""
    dim search as integer
    for search = val(text1) to val(text2)
    text3 = val(text3) + search
    next search

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Almost!!! replace the + with a &, because it are integers it'll add the previous value to the new one.

    Code:
    text3 = "" 
    dim search as integer 
    for search = val(text1) to val(text2) 
    text3 = val(text3) & search 
    next search
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4
    Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    52
    I guess its a matter of interpetation. Mine will produce 15 in text3 while Jop's will produce 12345 in text 3

  5. #5
    Guest
    Difference:

    + = Add strings/get an answer
    & = Add to string(s)

    (Not just strings...integers/etc. as well)

  6. #6
    Addicted Member Ramandeep's Avatar
    Join Date
    Feb 2000
    Posts
    158
    A better and more pro answer would have been:

    '+' Sum up the two numbers whereas
    '&' concatenates them together.

    If your a biginner I suggest getting the following book it's very good recomended by my programming teacher.

    Tite: Visual Basic 6 How to Program
    Author: Deitel & Deitel & Nieto (A father & son book)

    It will teach from beginer to intermediate/advance sort of level (covers graphics, database, internet, multimedia as well + more

    Also it lists good programming practice, bad programming practice, comon mistakes etc

    Top book!!!

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