Results 1 to 5 of 5

Thread: vb 6 understanding?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    2

    Post

    dim A as string, num1 as integer, num2 as integer
    num1=1
    num2=num*2
    for num1=1 to 10 sep num2
    A=A & str(num1+num2)
    next num1

    SOLVE A

    in this problem, what exactly is A=A & str(num1+num2)?

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    I'll explain it to you:

    Dim A As String, Num1 As Integer, Num2 As Integer
    Num1 = 1 ' Sets 1 to variable Num1
    Num2 = Num1 * 2 ' Sets a value two times bigger than Num1 to Num2 (this would be 2)
    For Num1 = 1 To 10 Step Num2 ' Loops Num1 from 1 to 10, stepping (Num2) ahead each time
    A = A & Str(Num1 + Num2) ' Adds Num1 to Num2, and puts the result in the end of string A
    Next Num1 ' Goes back to beginning of loop


    In the end, A should contain " 3 5 7 9 11". If you want to remove the spaces, then use Trim(Str(Num1 + Num2)) instead of Str(Num1 + Num2). The result would be "357911". On second thought... Leave the spaces...

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: RZvika@netvision.net.il
    ICQ: 19552879


    [This message has been edited by Yonatan (edited 11-09-1999).]

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Post

    It concatenates (joins together) the value of A with the sum of num1 plus num2 converted to a string. If you put a Msgbox A line following the line, you will see the result.

    ------------------
    Marty

  4. #4
    Junior Member
    Join Date
    Jan 1999
    Location
    Pierre, SD USA
    Posts
    23

    Post

    Shame on you Yonatan! You were doing good until you told him what the final value of A is. It looks to me as if you just answered someone's homework question!

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    2

    Post

    so, the way I see it/ the result should be as follows:
    num1 num2=num1*2 num1+num2
    1 2 3
    3 6 9
    5 10 15
    7 14 21
    9 18 27
    therefore the answer is: 39152127. Is this correcr?

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