|
-
June 26th, 2012, 03:08 AM
#1
Allowing only number in the textbox
i want text box only needs to allowed numeric no .in other way round . i need to adapt the following code in vb.net .let me know please .
Code:
Private Sub TxtWeekNo_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Or KeyAscii = 27 Or KeyAscii = 13 Then Exit Sub 'we need to allow backspace & some other key
If Not (KeyAscii > 47 And KeyAscii < 58) Then
KeyAscii = 0
End If
End Sub
-
June 26th, 2012, 04:46 AM
#2
Re: Allowing only number in the textbox
-
June 26th, 2012, 09:48 AM
#3
Re: Allowing only number in the textbox
Not sure how KeyAscii gets to this Sub. Looks like it is a number already. If you are asking about how to test a value in a text box you can use the IsNumeric function.
-
June 26th, 2012, 09:53 AM
#4
Re: Allowing only number in the textbox
 Originally Posted by Mur16
Not sure how KeyAscii gets to this Sub. Looks like it is a number already. If you are asking about how to test a value in a text box you can use the IsNumeric function.
That was VB 6 code, that the OP wants to 'convert' into .NET
-
June 26th, 2012, 10:06 AM
#5
Re: Allowing only number in the textbox
I see . . .
Code:
Private Sub TxtWeekNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtWeekNo.TextChanged
' test to see if TxtWeekNo.Text IsNumeric
End Sub
-
June 26th, 2012, 10:13 AM
#6
Re: Allowing only number in the textbox
I agree with your test for IsNumeric. The problem I can foresee here is the fact that sometimes special keys also needs allowance. Keys such as the Backspace, perhaps even the Delete key should be allowed. Another thing to consider here is the formatting of the numbers, ie, the presenting of them. Will decimals be allowed. Will a thousands-separator be needed and so forth. I was initially thinking about the Masked Edit Box, but decided to go with the VBForums link, as it is more useful at the end of the day
-
June 26th, 2012, 11:21 AM
#7
Re: Allowing only number in the textbox
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|