3 Replies - 4411 Views - Last Post: 10 February 2010 - 07:48 PM Rate Topic: -----

#1 Guest_sandvader*


Reputation:

Validate string in text box

Posted 10 February 2010 - 12:21 PM

I have a form that a user inputs either A B C or D into a text box. I need to validate that one of those four letters has been entered in the text box. I am using a case statement but I think an array might work better but I can't figure out how to validate a string in an array. If someone has a sample or there is a tutorial on this please let me know.
Or if there is a better way to use the case statement...Here is my code snippet
This works, but it seems like it is the long way to do it. Also as soon as I click OK on the message box it immediatly goes and shows my next form. How do I get it validate, let the user redo, and then bring up the other form? I got a feeling I am really lost and there are two many issues here to address, but any help would be appreciated!
 
Private Sub btnScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScore.Click
        
        Select Case txt1.Text
            Case Is = "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
                MessageBox.Show("Please choose a letter A B C or D")
        End Select

        Dim Grades As New frmGrades() ' Declare an instance
        Grades.ShowDialog()                ' Display the form

    End Sub



Is This A Good Question/Topic? 0

Replies To: Validate string in text box

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6111
  • View blog
  • Posts: 23,671
  • Joined: 23-August 08

Re: Validate string in text box

Posted 10 February 2010 - 02:32 PM

Moved to VB.NET
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,200
  • Joined: 25-September 09

Re: Validate string in text box

Posted 10 February 2010 - 02:43 PM

You're close

Try changing your line to
Case "e" to "z"



Also in your select case statement I would use
Select Case Txt1.Text.ToLower


This way if the user types A it will be converted to lower case for the check.

This post has been edited by CharlieMay: 10 February 2010 - 02:44 PM

Was This Post Helpful? 1
  • +
  • -

#4 sandvader  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 08-August 09

Re: Validate string in text box

Posted 10 February 2010 - 07:48 PM

Very good idea on the ToLower section! Totally didn't think of that. The Case e to z I knew I could do that with numbers but didn't think I could do that with the alphabet. Genius!

View PostCharlieMay, on 10 February 2010 - 01:43 PM, said:

You're close

Try changing your line to
Case "e" to "z"



Also in your select case statement I would use
Select Case Txt1.Text.ToLower


This way if the user types A it will be converted to lower case for the check.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1