473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2247
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.