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

Universal function to check for entered digits only

Hello,

I'd like to create a function that will allow users to only enter
numbers in some textboxes. I'm trying to create only one function and
call it for each textbox.keypress event instead of creating one for
each textbox.

This is what I have (and works):

Private Function DigitsOnly(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles _
txtOrderNumber.KeyPress

' set the Order Number textbox to accept only digits, the
Backspace, the Tab, or the Enter key.
If Not (Char.IsNumber(e.KeyChar) OrElse AscW(e.KeyChar) = 8
OrElse AscW(e.KeyChar) = 9 OrElse AscW(e.KeyChar) = 13) Then
e.Handled = True
End If

End Function

However, how do I create it without stating the textbox handler
(Handles txtOrderNumber.KeyPress) so I can call it from any textbox,
pass the textbox name as the object to be handled and then execute it?

For example,

' call the DigitsOnly function
DigitsOnly(txtMyOtherTextBox.name)
Right now if I try to create a variable for this and use it I get an
error stating "Handles clause requires a WithEvents variable).

Thanks for all your help guys (and gals)!

J

May 17 '07 #1
1 1323
John Smith <IL***@NETZERO.NETwrote in news:1179421544.046665.265210
@h2g2000hsg.googlegroups.com:
I'd like to create a function that will allow users to only enter
numbers in some textboxes. I'm trying to create only one function and
call it for each textbox.keypress event instead of creating one for
each textbox.
How about creating a custom order number textbox?
May 17 '07 #2

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
7
by: Stefan Richter | last post by:
Hi, I am looking for a good function to check if a entered value is a money value - meaning it's a decimal with no more then 2 digits after the point. Thanks, Stefan
2
by: Skybuck Flying | last post by:
I have finally figured out what the hell it is I invented :) It's another universal code: http://en.wikipedia.org/wiki/Universal_code I shall name this code: Skybuck's universal code...
9
by: Henke | last post by:
Hi! Is there a simple way to check if a string entered in a text box is a valid integer? Thanks in advance! /Henke
33
by: news.microsoft.com | last post by:
To Microsoft and fellow MSDN Universal subscribers... Regarding new MSDN Universal (I mean Premier) price and level changes: 1) Way too expensive for the small and medium developer Universal...
27
by: Luke Wu | last post by:
Is there a C function that returns the number of digits in an input int/long? example: numdigits(123) returns 3 numdigits(1232132) returns 7
5
by: eyoung | last post by:
I have a function to check a string to make sure it is 6 digites using the trigger onBlur="CkFrmt(this)" Problem is I've got 4 fields in a row...if I enter a wrong number in the first and hit tab...
8
mmarif4u
by: mmarif4u | last post by:
Hi everybody... I want to enter values to db like the following,,, Format is like this (810605-14-6356) This is the rite format, No a to z letters... 6 digits then - then 2 digits then - then 4...
2
by: andersond | last post by:
I am creating a website that will allow retail insurance agents to enter enough information on a commercial truck to get a quote. I have a function called "item" that validifies the data entered...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.