473,386 Members | 1,721 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,386 software developers and data experts.

controlling the input into a textbox

Does anyone know how can ensure that the only input that is accepted into a textbox is a numeric (only digits 1-9 accepted)

Is this possible

I am using vb.net to create a windows app

thx folks
Jul 21 '05 #1
5 1543
Cor
Hi Massy,

1-9 or 0 to 9?

Cor
Jul 21 '05 #2
Cor
Hi Massy,

Does not matter, this is a sample as you was asking.

Try it, I hope this helps?

Cor

Private Sub textbox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles textbox1.KeyUp
If e.KeyValue <> 8 Then
If Not IsNumeric(textbox1.Text) OrElse CInt(textbox1.Text) = 0
MessageBox.Show("Only 1 to 9 is allowed")
textbox1.Focus()
End If
End If
End Sub
Jul 21 '05 #3
Private Sub TextBox_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If Char.IsControl(e.KeyChar) Then
Exit Sub
End If
If Not Char.IsNumber(e.KeyChar) Then
e.Handled = True
End If
End Sub
HTH
Rigga.

"Massy" <an*******@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
Does anyone know how can ensure that the only input that is accepted into a textbox is a numeric (only digits 1-9 accepted)?
Is this possible?

I am using vb.net to create a windows app.

thx folks

Jul 21 '05 #4
Hi Cor

I tried your code and it worked fine. However it still leaves the character that has been pressed to remain in the textbox after the messagebox has been displayed. Is there anyway to remove the character that has just been input?

Rigga
I tried the example u gave me but i could not get it to work. Is there something im doin wrong
I replaced the textbox1 value in your code to the name of my textbox. Even i the user enters charcter values in this field, no action is taken! Is there something else i should be doin

thx
Jul 21 '05 #5
Hi Rigga, I have just got your code to work, I changed the mybase.Keypress to MyTextbox.Keypress

Thx for your code Cor and Rigga. It is appreciated
:o)
Jul 21 '05 #6

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

Similar topics

1
by: TB | last post by:
Hi All: I have this datagrid where space is very tight, and therefore I have to make sure that everything fits within a fixed screen width regardless of whether I am in list mode or in edit...
0
by: Giulio Santorini | last post by:
Hi, I've got two drop down list controls. When I select a value from the first one I fill the second one. And when I select a value from the second one I would like to fill another control. But...
0
by: Marcos Beccar Varela | last post by:
Hello to all. I need to control some objects from a module like the old VB 6 style. Can anyone help on how to do this? For example, I need that when BUTTON1 es pressed in FORM1.. with a TEXTBOX...
3
by: Adriana Camargo | last post by:
Hi I have to change automatically the text inside a textbox. I need to add thousand separator when I am writting in the textbox. I am using TextChanged event and when I insert a new number, i...
5
by: Massy | last post by:
Does anyone know how can ensure that the only input that is accepted into a textbox is a numeric (only digits 1-9 accepted) Is this possible I am using vb.net to create a windows app thx...
1
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
1
by: Mario Figueiredo | last post by:
Hello everyone, I'm having trouble controlling the cursor position when I make two consecutive calls to the get family of functions. This problem does not happen if there is an output in...
6
by: Paulers | last post by:
Hello, I am trying to manipulate a console based application from another application for example I need to launch the console application, provide it input and take the output from the console...
1
by: Cainnech | last post by:
Hello all, I have a big challenge ahead of me but I'm gonna need a lot of help from experts on this one. I have to create a system that can receive input from external devices. So when users...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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,...
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...

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.