Results 1 to 12 of 12

Thread: [RESOLVED] Textbox to Listbox with Validation

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    45

    Resolved [RESOLVED] Textbox to Listbox with Validation

    I am moving data from a textbox and listbox to validate each line individually, here is my code:

    VB Code:
    1. 'Move Textbox data to Listbox
    2.     strParts = Split(txtNotSequential.Text, vbCrLf)
    3.  
    4.     For lngIndex = 0 To UBound(strParts)
    5.         lstCheck.AddItem strParts(lngIndex)
    6.     Next
    7.    
    8.     txtNotSequential.Text = ""
    9.    
    10.     'Move Listbox data back to Textbox
    11.     For lngIndex = 0 To lstCheck.ListCount - 1
    12.    
    13.         'Checks to see if the number is not less than 11 digits long long
    14.         If Len(lstCheck) <> 11 Then
    15.                 MsgBox "Please enter a complete Mobile number including the " & vbCrLf & _
    16.                        "X mobile code 01234", vbInformation, "Invalid Mobile Number"
    17.                
    18.                 For lngIndex = 0 To lstCheck.ListCount - 1
    19.                
    20.                     txtNotSequential.Text = Left$(txtNotSequential.Text, Len(txtNotSequential.Text) - 2)
    21.                
    22.                 Loop
    23.                
    24.                 lstCheck.Clear
    25.            
    26.             Exit Sub
    27.  
    28.         'Checks to see if the mobile code has been entered
    29.         ElseIf Mid(lstCheck, 1, 5) <> "01234" Then
    30.                 MsgBox "Please enter the X Mobile Code 01234", vbInformation, "No need for code"
    31.            
    32.                 For lngIndex = 0 To lstCheck.ListCount - 1
    33.                
    34.                     txtNotSequential.Text = Left$(txtNotSequential.Text, Len(txtNotSequential.Text) - 2)
    35.                
    36.                 Loop
    37.                
    38.                 lstCheck.Clear
    39.            
    40.             Exit Sub
    41.  
    42.         End If
    43.    
    44.        txtNotSequential.Text = txtNotSequential.Text & lstCheck.List(lngIndex) & vbCrLf
    45.     Next
    46.  
    47.     lstCheck.Clear

    The problem I am having it that no matter what data is put into the textbox (even if it is correct) the first msgbox will error? Can anyone help with my coding?








    Added [RESOLVED] to thread title and green "resolved" checkmark - Hack
    Last edited by Hack; Jan 19th, 2006 at 10:02 AM.

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