Results 1 to 3 of 3

Thread: adding numbers in text boxes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    Post

    I know the basics about adding numbers in text boxes. For instance:

    Private Sub text4_KeyPress(keyascii As Integer)
    keyascii = Asc(Chr(keyascii))
    If Val(Text4.Text) = Val(Text1.Text) + Val(Text2.Text) And keyascii = vbKeyReturn Then
    Text3.Visible = True
    End If
    End Sub


    But the text box with the numbers that are added is a control array - and the number of text boxes in the array can vary (they can be created at run time).

    How can I add the numbers in the text boxes if the text box is an array? I thought something like below would do it, but it doesn't:

    Private Sub text4_KeyPress(keyascii As Integer)
    Dim index As Integer
    For index = 1 To Text1.UBound - 1
    keyascii = Asc(Chr(keyascii))
    If Val(Text4.Text) = Val(Text1.UBound) And keyascii = vbKeyReturn Then
    Text3.Visible = True
    End If
    Next index
    End Sub

    Any help would be much appreciated!

    Slan

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Post

    Code:
    i = 0
    Do While IsObject(Text1(i))
    Text1(i).Text = "1"
    i = i + 1
    Loop
    Edited by Phobic on 03-10-2000 at 03:26 PM

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    Post

    Phobic, I tried your code but it didn't work:

    Private Sub text4_KeyPress(keyascii As Integer)
    keyascii = Asc(Chr(keyascii))
    i = 0
    If Val(Text4.Text) = Val(Text2(i).Text) And keyascii = vbKeyReturn Then
    Picture4.Visible = True
    Picture5.Visible = False
    Do While IsObject(Text2(i))
    Text2(i).Text = "1"
    i = i + 1
    Loop
    End If
    End Sub

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