473,473 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

textbox

I am new to vb.net. I have a textbox. I want the user to be able to only
enter numbers between 2 and 12 into the textbox. Is there a way to do this?
Thanks for any help.
Nov 21 '05 #1
6 2251
Do you only want 2 digits? With CTRL + V (paste) will cause you a few more
problems

Why don't you use a spin button instead? That way you can specify min/max
values that the user can choose - problem solved
Nov 21 '05 #2
Steve,

You mean something as this typed in this message and not checked

\\\\
Private Sub TextBox1_Validating(ByVal sender _
As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox1.Validating
If Not Check12(TextBox1.Text) then messagebox.show ("The value is not
between 2 and 12")
End Sub
Private Function Check12(value) as boolean
If value > 0 Then
If IsNumeric(value) Then
If Cint(value) < 2 OrElse Cint(value) > 12 Then
return true
End if
end if
end if
End sub
///

I hope this helps a little bit?

Cor
Nov 21 '05 #3
"Steve" <kg******@hotmail.com> schrieb:
I am new to vb.net. I have a textbox. I want the user to be able to only
enter numbers between 2 and 12 into the textbox.


\\\
Imports System.ComponentModel
..
..
..
Private Sub TextBox1_Validating( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Validating
Dim SourceControl As TextBox = DirectCast(sender, TextBox)
Dim ErrorText As String
Try
Dim i As Integer = Integer.Parse(SourceControl.Text)
If i < 1 OrElse i > 12 Then
ErrorText = "Value must fall in the interval 1, ..., 12."
End If
Catch
ErrorText = "Value must be an integer."
End Try
Me.ErrorProvider1.SetError( _
SourceControl, _
ErrorText _
)
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
If you do this
'the public sub define is not correct, when you double click on textbox and
go to code add the event onchange

Public sub TextBox_Change(byval sender, byval e)
try
try
if((microsoft.visualbasic.right(cint(e.text),1) <= 2)) and
((microsoft.visualbasic.right(cint(e.text),1) >= 9) then
'if you want to make sure that the user does not have 'a
number larger then 12
if((cint(e.text)< 12) and (cint(e.text)>=2))then
'number betweeen 2 and 12
else
'number not between 2 and 12
me.textbox.text = microsoft.visualbasic.left
(me.textbox.text,(LEN(me.textbox.text)-1))
end if
else

me.textbox.text = microsoft.visualbasic.left
(me.textbox.text,(LEN(me.textbox.text)-1))
end if
end if
catch
'number was not entered
me.textbox.text = microsoft.visualbasic.left
(me.textbox.text,(LEN(me.textbox.text)-1))
end try

catch ex as

end try

end sub

"Steve" <kg******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am new to vb.net. I have a textbox. I want the user to be able to only
enter numbers between 2 and 12 into the textbox. Is there a way to do
this? Thanks for any help.

Nov 21 '05 #5
HerFried

If the user wants to allow only numbers between 2 and 12 why are you
checking for if i< 1? It should be If i<2

"Herfried K. Wagner [MVP]" wrote:
"Steve" <kg******@hotmail.com> schrieb:
I am new to vb.net. I have a textbox. I want the user to be able to only
enter numbers between 2 and 12 into the textbox.


\\\
Imports System.ComponentModel
..
..
..
Private Sub TextBox1_Validating( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Validating
Dim SourceControl As TextBox = DirectCast(sender, TextBox)
Dim ErrorText As String
Try
Dim i As Integer = Integer.Parse(SourceControl.Text)
If i < 1 OrElse i > 12 Then
ErrorText = "Value must fall in the interval 1, ..., 12."
End If
Catch
ErrorText = "Value must be an integer."
End Try
Me.ErrorProvider1.SetError( _
SourceControl, _
ErrorText _
)
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
"IHateAustrians" <IH************@discussions.microsoft.com> schrieb:
[...]


Rules of Conduct
<URL:http://www.microsoft.com/communities/conduct/default.mspx#ECAA>

Show that you are able to learn from your mistakes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jonas L | last post by:
Hi, I need to create a textbox which acts as a normal textbox but with the following extra requirements: 1) In-focus color, when the textbox gets focus the backcolor property of the textbox...
4
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with...
0
by: Newasps | last post by:
Hi guys, I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
2
by: Mamatha | last post by:
Hi I want to add an icon to the textbox's text. I don't know how to display icon in textbox in VB.NET. If any one knows please let me know. Thanks in advance. Mamatha
3
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. ...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
8
by: Marco Pais | last post by:
Hi there. How can I change the background color of a textbox when it gets the focus? I can handle the "Enter" event and do this private void txtDummie_Enter(object sender, EventArgs e) { ...
1
by: Andy B | last post by:
I have this code: protected void EditEventsWizard_NextButtonClick(object sender, WizardNavigationEventArgs e) { //get the values from the DetailsView TextBox StartTime =...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.