i am trying to set a key press event to accept only letters a-z and back space no numbers but im not sure how to word it can anyone help?
you just to handle keychar, but you must know the ascii of letters. this following code will not allowed you to input other character except letters or strings. so u cannot input number or other special character.
try this following code :
Private Sub textDate_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textDate.KeyPress If (Microsoft.VisualBasic.Asc(e.KeyChar) < 65) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 90) _ And (Microsoft.VisualBasic.Asc(e.KeyChar) < 97) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 122) Then 'space accepted If (Microsoft.VisualBasic.Asc(e.KeyChar) <> 32) Then e.Handled = True End If End If If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then e.Handled = False End If End Sub
This post really helped me. I have another question, continuation to before thread. I dont how to code for textbox keypress, where i want user to enter only numbers (e.g. 0009, 0010.. so on..) and deny rest.
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8) Then e.Handled = True End If End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e as System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Not Char.IsDigit(e.KeyChar) Then e.Handled = True End If End Sub
Edited 6 Years Ago by Luc001: n/a
I'm glad you got it helpful. If you want to ask question, start your own thread. Please do not resurrect old or solved threads.
Please read before posting - http://www.daniweb.com/forums/faq.php?faq=daniweb_policies and http://www.daniweb.com/forums/thread78223.html
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...