•
•
•
•
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 429,818 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,432 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: 3751 | Replies: 7
![]() |
•
•
Join Date: Feb 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
I need to be able to limit the text entered into a text box, I need to make it so that only whole numbers can be entered and not decimal places. I have already limited it to just Numbers but need help with this. I think checking a box to see if a fullstop is in it would be a good way but i dont know the command for searching a string.
•
•
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,585
Reputation:
Rep Power: 11
Solved Threads: 235
try this following code, this code only allowed number entered on textbox :
vb Syntax (Toggle Plain Text)
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 sub
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Jan 2008
Posts: 24
Reputation:
Rep Power: 1
Solved Threads: 0
Hi
Try the following code So that you can enter only the numbers not even any special characters.
try it in the textbox keypress event
Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tsum.KeyPress
If Asc(e.KeyChar) = 8 Then
Exit Sub
End If
If Asc(e.KeyChar) = 44 Then
e.Handled = True
End If
If Asc(e.KeyChar) < 48 Then
e.Handled = True
ElseIf Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End Sub
Try the following code So that you can enter only the numbers not even any special characters.
try it in the textbox keypress event
Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tsum.KeyPress
If Asc(e.KeyChar) = 8 Then
Exit Sub
End If
If Asc(e.KeyChar) = 44 Then
e.Handled = True
End If
If Asc(e.KeyChar) < 48 Then
e.Handled = True
ElseIf Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End Sub
•
•
Join Date: Jan 2008
Posts: 65
Reputation:
Rep Power: 1
Solved Threads: 4
•
•
•
•
I need to be able to limit the text entered into a text box, I need to make it so that only whole numbers can be entered and not decimal places. I have already limited it to just Numbers but need help with this. I think checking a box to see if a fullstop is in it would be a good way but i dont know the command for searching a string.
You could also use the IsNumeric to insure all numbers and then check for the (.) as the other answer stated.
The MaxLength function will limit the number of characters.
You could also use code to check on keydown event if the character being enter is a number or period. If the period is captured, trigger a messagebox event and remove the period and reset the focus at the end of the numeric string.
•
•
Join Date: Jan 2008
Posts: 65
Reputation:
Rep Power: 1
Solved Threads: 4
•
•
•
•
Hi
Try the following code So that you can enter only the numbers not even any special characters.
try it in the textbox keypress event
Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tsum.KeyPress
If Asc(e.KeyChar) = 8 Then
Exit Sub
End If
If Asc(e.KeyChar) = 44 Then
e.Handled = True
End If
If Asc(e.KeyChar) < 48 Then
e.Handled = True
ElseIf Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End Sub
If IsNumeric(TextBox1.Text) And TextBox1.Text.Contains(".") Then
MsgBox("True for .")
Else
MsgBox("False for .")
End If
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- limiting the input in text box (Visual Basic 4 / 5 / 6)
- inputting a single character in a textbox (Visual Basic 4 / 5 / 6)
- multiple search terms+fulltext search (MySQL)
- Having trouble Subtracting 3 digit #'s help! (VB.NET)
- Select Box populates text field (JavaScript / DHTML / AJAX)
- Hi,Need help on sql select statement structure (MS SQL)
- Php newsletter error (PHP)
- not-a-virusadware (Viruses, Spyware and other Nasties)
- How do I limit text char in Combo box? (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: how to make a textbox with inputs are on the button
- Next Thread: Creating a coundown timer in a form



Linear Mode