Results 1 to 4 of 4

Thread: validation in array

  1. #1

    Thread Starter
    Member NeOn_BoY's Avatar
    Join Date
    Feb 2002
    Location
    In the magic server in the sky!!
    Posts
    60

    validation in array

    how would i code some kind of validation into this peice of code so it only accepts numbers?? maybe case statements// help

    Private Sub Command2_Click()
    For this = 1 To 18
    num = InputBox("Please enter your scores")
    nos(this) = num
    If nos(this) < 1 Then
    MsgBox "Error please enter a valid number > 0"
    this = this - 1
    End If
    Next this
    For Counter = 1 To 18
    Text1 = Text1 & " | " & nos(Counter)
    Next Counter
    End Sub

    is there any way to take an array back a loop if the dat entered doesnt meet the required format.

  2. #2
    Member
    Join Date
    Nov 2001
    Location
    Lincoln,England
    Posts
    60
    Could use isnumeric()

  3. #3

    Thread Starter
    Member NeOn_BoY's Avatar
    Join Date
    Feb 2002
    Location
    In the magic server in the sky!!
    Posts
    60

    more help

    what does that mean and who so i set it out i dont understand

  4. #4
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828

    Re: validation in array

    try this:

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim nos(18) As Integer
    3.     Dim str As String
    4.     Dim i As Integer
    5.    
    6.     For i = 0 To 17
    7.         str = ""
    8.         Do
    9.             Do
    10.                 str = InputBox("Please enter your scores")
    11.                 If Not IsNumeric(str) Then MsgBox "Must be numerical!"
    12.             Loop Until IsNumeric(str)
    13.             If Val(str) < 1 Then
    14.                 MsgBox "Error please enter a valid number > 0"
    15.             End If
    16.         Loop Until Val(str) > 0
    17.         nos(i) = Val(str)
    18.     Next i
    19.    
    20.     For i = 0 To 17
    21.         Text1 = Text1 & " | " & nos(i)
    22.     Next i
    23. End Sub
    Last edited by darre1; Feb 8th, 2002 at 11:59 AM.
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

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