Results 1 to 2 of 2

Thread: Val - getting sums and values

  1. #1

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

    Hi,

    Is there a way to code all the integers in a control array rather than: Val(Text3(0).Text) + Val(Text3(1).Text)+
    Val(Text3(2).Text) + Val(Text3(3).Text) + Val(Text3(4).Text) + Val(Text3(5).Text)....etc?


    For example:

    Private Sub Text5_KeyPress(keyascii As Integer)
    keyascii = Asc(Chr(keyascii))
    If Val(Text5.Text) = Val(Text3(0).Text) + Val(Text3(1).Text) + Val(Text3(2).Text) + Val(Text3(3).Text) + Val(Text3(4).Text) + Val(Text3(5).Text And keyascii = vbKeyReturn Then
    Textcorrect.Text = "Correct!"
    End If
    End Sub

    Thanks for any help!

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    you could loop through them...


    Code:
    Private Sub Text5_KeyPress(keyascii As Integer)
    
    Dim i As Integer
    Dim total As Integer
    
    For i = 0 To Text3.UBound
      total = total + Val(Text3(i).Text)
    Next
    
    If (Val(Text5.Text) = total) And (keyascii = vbKeyReturn) Then
      Textcorrect.Text = "Correct!"
    End If
    End Sub
    Mark
    -------------------

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