• Variable of TextBox (XL97;SR2)

    Author
    Topic
    #383693

    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

    Viewing 0 reply threads
    Author
    Replies
    • #655111

      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,

      • #655121

        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

        • #655147

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

        • #655302

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

          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
          
        • #655425

          This doesn’t seem impossible, it just ins’t elegant.

          For I = 1 to 15
             DO YOUR STUFF
             IF I = 3 then
                I = 6
             END IF
          NEXT I
          
    Viewing 0 reply threads
    Reply To: Variable of TextBox (XL97;SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: