473,763 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.keypres s event instead of creating one for
each textbox.

This is what I have (and works):

Private Function DigitsOnly(ByVa l sender As System.Object, ByVal e As
System.Windows. Forms.KeyPressE ventArgs) 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(txtM yOtherTextBox.n ame)
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 1340
John Smith <IL***@NETZERO. NETwrote in news:1179421544 .046665.265210
@h2g2000hsg.goo glegroups.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.keypres s 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
4964
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 webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
7
5195
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
1475
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 (pseudo name)
9
19699
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
2717
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 subscriber (and some large ones as well). $10,000 - $15,000 per user?!? Forget it! 2) Do you (MS) honestly believe that the market you are targeting will just buy this product on good faith? Without our recommendations? Think about
27
31375
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
2546
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 I get the error message and my script tries to move the focus to the first item...but because I hit the tab the focus in already on the second item which does not contain a 6 digit value so I must kill the page. help! function CkFrmt(str) {
8
1928
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 digits. dbConnect('db');
2
1921
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 into a text field. It has worked for 6 months; but, now it has quit working. However if I change the name from "item" to "bozo" it works. What gives here? <input type="text" name="modelYear1" id="modelYear1" disabled="disabled"...
0
9386
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
10145
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
9938
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,...
1
7366
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
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.