473,609 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
+ 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 2276
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_Valida ting(ByVal sender _
As Object, ByVal e As System.Componen tModel.CancelEv entArgs) _
Handles TextBox1.Valida ting
If Not Check12(TextBox 1.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******@hotma il.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.Componen tModel
..
..
..
Private Sub TextBox1_Valida ting( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Valida ting
Dim SourceControl As TextBox = DirectCast(send er, TextBox)
Dim ErrorText As String
Try
Dim i As Integer = Integer.Parse(S ourceControl.Te xt)
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.ErrorProvide r1.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.v isualbasic.righ t(cint(e.text), 1) <= 2)) and
((microsoft.vis ualbasic.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.visua lbasic.left
(me.textbox.tex t,(LEN(me.textb ox.text)-1))
end if
else

me.textbox.text = microsoft.visua lbasic.left
(me.textbox.tex t,(LEN(me.textb ox.text)-1))
end if
end if
catch
'number was not entered
me.textbox.text = microsoft.visua lbasic.left
(me.textbox.tex t,(LEN(me.textb ox.text)-1))
end try

catch ex as

end try

end sub

"Steve" <kg******@hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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******@hotma il.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.Componen tModel
..
..
..
Private Sub TextBox1_Valida ting( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Valida ting
Dim SourceControl As TextBox = DirectCast(send er, TextBox)
Dim ErrorText As String
Try
Dim i As Integer = Integer.Parse(S ourceControl.Te xt)
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.ErrorProvide r1.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.mi crosoft.com> schrieb:
[...]


Rules of Conduct
<URL:http://www.microsoft.c om/communities/conduct/default.mspx#EC AA>

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
2112
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 should be set to a, selectable, in-focus color. 2) Out-of-focus color, when the textbox loses focus the backcolor property of the textbox should be set to a, selectable, out-of-focus color.
4
2905
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 some textboxes not updating when i a hit save. for example I have this code in my aspx.cs file: declared:
0
1808
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 first values for each control. Please help me. Thanks for any help. Bye Ozer And here's my code: Imports System Imports System.Data Imports System.Data.OleDb
7
2109
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 following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
11
4534
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 opinion of how I want to handle the 'user experience' in the application I'm creating. While I know I could allow the user to enter in number and alpha text - in a text box - and then tell them when the execuate a command "This is not numeric data", I...
2
19849
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
2212
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. But while trying to insert a text box to see when a method is used, and putting a counter to bump some variable? The textbox sits there unchanged. I put a breakpoint at the text write
0
2392
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 View I want the form populated from there profile on the sql server. The code to save the profile works fine. But when the user logs back in they data doesn't load back to the form. The multiview is located inside the LoginView's Logged-In View ....
8
36878
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) { txtDummie.BackColor=Color.Red; }
1
1618
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 = (TextBox)EditEventForm.Rows.Cells.Controls; TextBox EndTime = (TextBox)EditEventForm.Rows.Cells.Controls;
0
8130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8076
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8573
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8222
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7002
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4021
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1672
muto222
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.