Click here to Skip to main content
16,016,391 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text <> " " Then
            ListBox1.Items.Add(TextBox1.Text)
            TextBox1.Text = " "
    End If
    End Sub
End Class
Posted
Comments
Sergey Alexandrovich Kryukov 14-Feb-14 0:58am    
Very bad unreliable code. What do you want to achieve? So far, the question does not make any sense at all...
—SA

1 solution

Method 1

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       If TextBox1.Text.Trim <> "" Then
           If Char.IsLetter(Me.TextBox1.Text) Then
               ListBox1.Items.Add(TextBox1.Text)
               TextBox1.Text = ""
           Else
               MsgBox("Please enter characters only", MsgBoxStyle.Exclamation, "Character Alert")
           End If
       End If
   End Sub


Method 2

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text.Trim <> "" Then
                           ListBox1.Items.Add(TextBox1.Text)
                TextBox1.Text = ""
                  End If
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Check_character(e)
    End Sub

    Sub Check_character(ByVal e As System.Windows.Forms.KeyPressEventArgs)
        If Char.IsLetter(e.KeyChar) = False And (Asc(e.KeyChar) <> 13) And (Asc(e.KeyChar) <> 8) And Char.IsWhiteSpace(e.KeyChar) = False Then
            e.Handled = True
            MsgBox("Only Characters Allowed", MsgBoxStyle.Exclamation, "Character Alert")
        End If
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900