PC Review


Reply
Thread Tools Rate Thread

controlling the input into a textbox

 
 
=?Utf-8?B?TWFzc3k=?=
Guest
Posts: n/a
 
      23rd Feb 2004
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
 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      23rd Feb 2004
Hi Massy,

1-9 or 0 to 9?

Cor


 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      23rd Feb 2004
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


 
Reply With Quote
 
Rigga
Guest
Posts: n/a
 
      23rd Feb 2004
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" <(E-Mail Removed)> wrote in message
news:2063BDDF-FD62-413F-B16D-(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?TWFzc3k=?=
Guest
Posts: n/a
 
      23rd Feb 2004
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
 
Reply With Quote
 
=?Utf-8?B?TWFzc3k=?=
Guest
Posts: n/a
 
      23rd Feb 2004
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
)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling Input TeeSee Microsoft Access Form Coding 1 16th Dec 2008 12:30 AM
textbox -- can't switch input mode until after textbox is fullscreen rpatel4@gmail.com Microsoft Dot NET Compact Framework 1 19th Sep 2006 11:35 PM
Controlling Input Cameron Microsoft Excel Programming 2 9th Apr 2004 02:03 PM
Help, Controlling Input Reia Microsoft Access Form Coding 1 10th Feb 2004 08:16 PM
Enter Day in textbox based on day input in previous textbox Sue M Microsoft Access Forms 1 8th Aug 2003 10:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:01 AM.