•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 455,988 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,790 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 5663 | Replies: 13
![]() |
•
•
Join Date: Oct 2007
Posts: 16
Reputation:
Rep Power: 2
Solved Threads: 0
Hi. I need TextBox in which user can input only numbers. I found some examples about it, but can't do them. For example in the following code
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not (e.KeyChar.IsDigit(e.KeyChar)) And _
e.KeyChar <> ChrW(Keys.Back) Then
e.Handles = True
End If
End Sub
VB underline this
e.Handles = True ' because Handles is not member of "System.Windows.Forms.KeyPressEventArgs"
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not (e.KeyChar.IsDigit(e.KeyChar)) And _
e.KeyChar <> ChrW(Keys.Back) Then
e.Handles = True
End If
End Sub
VB underline this
e.Handles = True ' because Handles is not member of "System.Windows.Forms.KeyPressEventArgs"
•
•
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,590
Reputation:
Rep Power: 11
Solved Threads: 236
You must to specify the character in ascci that contains numbers only
Try This following code :
Jery
Best Regards
Try This following code :
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _
Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
e.Handled = True
End If
If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
e.Handled = False
End If
end subJery
Best Regards
Last edited by Jx_Man : Dec 6th, 2007 at 1:05 am. Reason: explaination
try this,it will definatly work
Private Function TrapKey(ByVal KCode As String) As Boolean
If (KCode >= 48 And KCode <= 57) Or KCode = 8 Then
TrapKey = False
Else
TrapKey = True
End If
End Function
//textbox keypress event
e.Handled = TrapKey(Asc(e.KeyChar)) Last edited by cscgal : Dec 6th, 2007 at 2:30 pm. Reason: Added code tags
•
•
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,444
Reputation:
Rep Power: 4
Solved Threads: 87
Hi,
Try This :
Regards
Veena
Try This :
vb Syntax (Toggle Plain Text)
Private Sub Text1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Text1.KeyPress If e.KeyChar <> ChrW(Keys.Back) Then If (e.KeyChar.ToString >= "A" And e.KeyChar.ToString <= "Z") Or (e.KeyChar.ToString >= "a" And e.KeyChar.ToString <= "z") Then Else e.Handled = True End If End If End Sub
Regards
Veena
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Numeric TextBox (C#)
- How to restrict the entry of alphabets in a textbox using javascript...? (JavaScript / DHTML / AJAX)
- text box validataion (ASP.NET)
- To display data in textbox and label (Visual Basic 4 / 5 / 6)
- calculating sum, average, highest and lowest grades (Visual Basic 4 / 5 / 6)
- Entering text into existing webform (VB.NET)
- Limitation (ASP.NET)
- Call Function (ASP.NET)
- Text printing is giving me trouble (C#)
Other Threads in the VB.NET Forum
- Previous Thread: Starting application
- Next Thread: debugging problem



Linear Mode