How to Validate 9 Letter Target Words in VB.Net

Asked By 20 points N/A Posted on -
qa-featured

A friend asked me to create a puzzle program which finds 9 letter target words in a 3 by 3 letter grid. I decided to use VB.Net 2010. But, I can't determine if the words are valid. How could I verify the 9 letter target words?

SHARE
Answered By 0 points N/A #133388

How to Validate 9 Letter Target Words in VB.Net

qa-featured

Hello,

You can simply use the method such as validating text boxes and write up your code to suit your 9 letter target word. An example of validation code for text boxes is as shown below.

Private Sub btn1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btn1.Click

  If (txt1.Text.Trim = "") Then
    MsgBox("Blank not Allowed", MsgBoxStyle.Information, "Verify")
  Else
    MsgBox(txt1.Text, MsgBoxStyle.Information, "Verify")
  End If

  txt1.Clear()
  txt1.Focus()
End Sub

Private Sub txt1_KeyPress(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.KeyPressEventArgs) _
        Handles txt1.KeyPress
  If (Char.IsControl(e.KeyChar) = False) Then
    If (Char.IsLetter(e.KeyChar)) Or (Char.IsWhiteSpace(e.KeyChar)) Then
      'do nothing
    Else
      e.Handled = True
      MsgBox("Sorry Only Character & Spaces Allowed!!", _
             MsgBoxStyle.Information, "Verify")
      txt1.Focus()
    End If
  End If
End Sub

Private Sub txt2_KeyPress(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.KeyPressEventArgs) _
        Handles txt2.KeyPress
  If (Char.IsControl(e.KeyChar) = False) Then
    If (Char.IsDigit(e.KeyChar)) Then
      'do nothing
    Else
      e.Handled = True
      MsgBox("Sorry Only Digits Allowed!!", _
             MsgBoxStyle.Information, "Verify")
      txt2.Focus()
    End If
  End If
End Sub

Private Sub btn2_Click(ByVal sender As System.Object, _
         ByVal e As System.EventArgs) Handles btn2.Click
  If (txt2.Text.Trim = "") Then
    MsgBox("Blank not Allowedt", MsgBoxStyle.Information, "Verify")
  Else
    MsgBox(txt2.Text, MsgBoxStyle.Information, "Verify")
  End If

  txt2.Clear()
  txt2.Focus()
End Sub

Thank you.

Login/Register to Answer

Related Questions