Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variable of TextBox (XL97;SR2)

    Is it possible to do the following:

    Private Sub CommandButton1_Click()
    For i = 1 To 3
    TextBox18 = Val(TextBox18) + Val(TextBox & i)
    Next
    End Sub

    The end result should be the accumulated amount from the value in Textbox1, Textbox2 and Textbox3. If the values in each of the three textboxes previously mentioned are zero the end result is 6. This is the result of the "For i 1 To 3" it is adding the 1, 2 and 3 to get 6. I've tried other code but can not get it to do what I want.

    Your assistance is appreciated.
    John

  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable of TextBox (XL97;SR2)

    hi John,

    only a minor modification needed:

    Private Sub CommandButton1_Click()
    For i = 1 To 3
    TextBox18 = Val(TextBox18) + Val(controls("TextBox" & cstr(i)))
    Next
    End Sub

    greetings,

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable of TextBox (XL97;SR2)

    Pieter,

    Thank you it worked. One more thing comes to mind. Is it possible to do something like this: For i 1 To 3 and For i 7 to 15

    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Variable of TextBox (XL97;SR2)

    No, you'll have to write two separate For ... Next loops.

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable of TextBox (XL97;SR2)

    Yes (sorry Hans) as long as the number of values that I takes on is fairly small:

    <pre>Dim I As Variant
    For Each I In Array(1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15)
    MsgBox I
    Next I
    </pre>

    Legare Coleman

  6. #6
    2 Star Lounger
    Join Date
    May 2002
    Location
    Midland, Michigan, USA
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable of TextBox (XL97;SR2)

    This doesn't seem impossible, it just ins't elegant.
    <pre>For I = 1 to 15
    DO YOUR STUFF
    IF I = 3 then
    I = 6
    END IF
    NEXT I
    </pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •