473,473 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

textbox in vb accepting characters and numbers only

103 New Member
Hi all
Wonder if anyone can help me out to solve this:

please find the code of textbox that accepts only characters and
one textbox that accepts only numbers:

(vb)
textbox for accepting characters:
If txtname.Text = "" Then
MsgBox "enter the name", vbOKOnly, "PAYROLL"
txtname.SetFocus
Exit Sub
ElseIf IsNumeric(txtname.Text) Then
MsgBox "enter name",vbOKOnly, "PAYROLL"
With txtname
.SelStart = 0
.SelLength = Len(txtname.Text)
.SetFocus
End With
End If

wat change i need for above code:?
if i press ny numbers instead that should not be displayed inside the
textbox

code:vb
textbox for accepting numbers

Private Sub txtid_KeyPress(KeyAscii As Integer)
If (KeyAscii > 47 And KeyAscii < 58) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End Sub

WAt change i need for above code:"
backspace is not working
and also i dont need a

isnumeric(txtid.text)
code

please go thru this...and give a solutiion

Thanks in advance
Dec 19 '07 #1
2 7917
debasisdas
8,127 Recognized Expert Expert
You need to handle key ascii in the proper range and handle ascii=8 for backspace.
Dec 19 '07 #2
lotus18
866 Contributor

textbox for accepting numbers

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtid_KeyPress(KeyAscii As Integer)
  2. If (KeyAscii > 47 And KeyAscii < 58) Then 
  3. KeyAscii = KeyAscii
  4. Else
  5. KeyAscii = 0
  6. End If
  7. End Sub
Hi

Change your code with this one:

Expand|Select|Wrap|Line Numbers
  1. If KeyAscii = 8 Or KeyAscii = vbKeyDecimal Then
  2.         KeyAscii = 8
  3. Else
  4.         If KeyAscii < 48 Or KeyAscii > 57 Then
  5.             KeyAscii = 0
  6.         End If
  7. End If
Rey Sean
Dec 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: anonieko | last post by:
This applies to javascript dynamic textbox onkey > > > Newsgroups: comp.lang.javascript From: Lasse Reichstein Nielsen <l...@hotpop.com> - Find messages by this author Date: Fri, 15 Jul 2005...
3
by: Bisley | last post by:
I wish to restrict my textbox to only accepting numbers I have looked the textbox KeyDown event and can inspect KeyEventArgs parameter and interogate which key has been pressed, but I can't work...
2
by: mg | last post by:
The simple e-mail webform in the shown in the code below sends the characters in its textbox as an email message correctly when text of any length is pasted into the textbox but not when large...
2
by: ae | last post by:
in C# for asp. i have a textbox, and at the point of doing an INSERT to my table, it is cutting it off at the point where end users press Return (the next line). in other words, in a multiline...
2
by: the friendly display name | last post by:
ASP.NET will generate a failure/security warning, if you enter html tags into a textbox (of course, the failure will come after the postback). That's nice and useful, and I know you can turn it...
2
by: Rain | last post by:
i have a method like this public void MethodName(byte data) { } and the textbox.text is the one suppying the argument to the method but my problem is its a string... how can i do this? any...
5
by: ameen.abdullah | last post by:
Hi Guys, I have a textbox in windows form that should only accept alphabets, numbers, spaces and underscore. If the textbox contains anyother character it should display a msg at the time of...
3
by: Michel Vanderbeke | last post by:
Hello, I would like to create a textbox with extra properties where I can choose if the textbox may contain only numbers, only letters, both, punctuation marks etc. Can anyone help me with tips...
1
by: bhappy | last post by:
Hai, I want to validate a textbox in clientside and im using the following code. Regular Expression Validator Exp: " .{250}.* " --> It means minimum length of textbox should be...
0
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,...
0
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...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
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 ...

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.