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

in textbox only number should enter

In textbox i want to enter only number not any alphabates. please tell how i code that
Sep 8 '07 #1
17 5620
gits
5,390 Expert Mod 4TB
hi ...

what textboxes are you talking about? is it a webpage?

kind regards
Sep 9 '07 #2
JosAH
11,448 Expert 8TB
... and what language?

kind regards,

Jos
Sep 9 '07 #3
In visual basic i put a textbox and i want to enter in that textbox only numeric value alphabete are not allowed .please how can i do it
Sep 10 '07 #4
hi ...

what textboxes are you talking about? is it a webpage?

kind regards

In visual basic i put a textbox and i want to enter in that textbox only numeric value alphabete are not allowed .please how can i do it
Sep 10 '07 #5
... and what language?

kind regards,

Jos
In visual basic i put a textbox and i want to enter in that textbox only numeric value alphabete are not allowed .please how can i do it
Sep 10 '07 #6
r035198x
13,262 8TB
In visual basic i put a textbox and i want to enter in that textbox only numeric value alphabete are not allowed .please how can i do it
Moved to VB forum
Sep 10 '07 #7
Robbie
180 100+
Change Text1 to the name of your TextBox:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_Change()
  2.          Dim CurrentPos As Long
  3.          Dim CurrentChar As String
  4.  
  5.          CurrentPos = 1
  6.          While CurrentPos <= Len(Text1.Text)
  7.              CurrentChar = Mid(Text1.Text, CurrentPos, 1)
  8.  
  9.              If Not (Asc(CurrentChar) >= 48 And Asc(CurrentChar) <= 57) Then
  10.                  Text1.Text = Replace(Text1.Text, CurrentChar, "")
  11.              End If
  12.  
  13.              CurrentPos = CurrentPos + 1
  14.          Wend
  15.  
  16.     Text1.SelStart = Len(Text1.Text)
  17. End Sub
  18.  
If you want to also be able to enter a decimal point then change this one line:
If Not (Asc(CurrentChar) >= 48 And Asc(CurrentChar) <= 57) Then
into this one line:
Expand|Select|Wrap|Line Numbers
  1. If Not ((Asc(CurrentChar) >= 48 And Asc(CurrentChar) <= 57) or currentchar=".") Then
  2.  
Sep 10 '07 #8
thank u for code but it gives error that

Run time error 5:
Invalid proceduer call or argument

this line
If Not (Asc(CurrentChar) >= 48 And Asc(CurrentChar) <= 57) Then

why it is
Sep 11 '07 #9
Robbie
180 100+
Run time error 5:
Invalid proceduer call or argument

this line
If Not (Asc(CurrentChar) >= 48 And Asc(CurrentChar) <= 57) Then
You must not be using VB6 then.
Seems the version you're using doesn't have the Asc() function.
If anyone used to .NET knows its equivalent to Asc(), it would be nice to hear from them now. =P
Sep 11 '07 #10
QVeen72
1,445 Expert 1GB
In visual basic i put a textbox and i want to enter in that textbox only numeric value alphabete are not allowed .please how can i do it

Hi,

Write this in KeyPress Event of TextBox:

Expand|Select|Wrap|Line Numbers
  1. If keyAscii <> 8 Then
  2.   If Instr("0123456789", Chr(KeyAscii)) = 0 Then KeyAscii = 0
  3. End If
  4.  
REgards
Veena
Sep 11 '07 #11
hariharanmca
1,977 1GB
Hi,
Expand|Select|Wrap|Line Numbers
  1. If keyAscii <> 8 Then
  2.   If Instr("0123456789", Chr(KeyAscii)) = 0 Then KeyAscii = 0
  3. End If
  4.  
If keyAscii <> 8 Then
REgards
Veena
I think, you have to allow Ascii 13 also.
Sep 11 '07 #12
QVeen72
1,445 Expert 1GB
I think, you have to allow Ascii 13 also.
Ascii=13 = Enter key,
If She wants to write code to move to next Control for enter key, then she has to check and write code for that..
BCoz, VB will not move to next control for Enter key by itself

Regards
Veena
Sep 11 '07 #13
hariharanmca
1,977 1GB
Ascii=13 = Enter key,
If She wants to write code to move to next Control for enter key, then she has to check and write code for that..
BCoz, VB will not move to next control for Enter key by itself

Regards
Veena
Just think if she want to write code for any operation by keypress 13 then the above code change the Ascii to 0.
better allow Ascii 13.
Sep 11 '07 #14
QVeen72
1,445 Expert 1GB
Hi Hari,

Yes, thats what i wrote in last post, if she want to write any code, she has to check that Ascii code and Exit Sub. Write my code in the End,
She may want to write for other chars also, SpaceBar, . - / ..

REgards
Veena
Sep 11 '07 #15
hariharanmca
1,977 1GB
Hi Hari,

Yes, thats what i wrote in last post, if she want to write any code, she has to check that Ascii code and Exit Sub. Write my code in the End,
She may want to write for other chars also, SpaceBar, . - / ..

REgards
Veena
Okay, But; usually space never comes in numbers entry.

Thanks for All detail replies.
Sep 12 '07 #16
Killer42
8,435 Expert 8TB
I'm surprised nobody has suggested using the Masked Edit control. It allows you to control the type and format of data entered.
Sep 12 '07 #17
I really very thank my problem solved
Sep 12 '07 #18

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

Similar topics

2
by: RelaxoRy | last post by:
If I fill out the textfields properly with Name, Email etc in a row it is fine. But if I fill out, for example, my Name, then tab twice, it clears my entered value. How do I stop this? All I...
14
by: Adam Clauss | last post by:
I've an application which is using a multiline textbox to log the status of a fairly long procedure. "Updates" are made to the status by calling textbox.AppendText. As my task is fairly lengthy,...
1
by: David Smith | last post by:
What I want to be able to do: A textbox is available that the user can enter information into. Specifically (for the purposes of this post), the user is asked to enter a number, and that number...
3
by: John | last post by:
Hello, I'm fairly new in programming and was trying to input numbers in textbox fields. This works fine but I would like to use the Enter key as well to input a number in a textbox the way you...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
5
by: TS | last post by:
for some reason, it posts to the server, but no click events of any buttons on form fire. the button is the first one on the form. when the focus is inside the textbox, it doesnt' work. if i click...
1
by: Wayne | last post by:
There is probably a simple solution to this but: I have a textbox that is bound to a number field in a table. The field type is "double". If I enter a negative value directly into the table it...
5
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a...
3
by: Mike | last post by:
Is there a way to determine if a user deleted text in a asp:textbox? I have a textbox were users can enter in a product number, then they click a button to see if the product numbers(s) exists in...
4
by: billa856 | last post by:
Hi, My Project is in MS Access 2002. In that I have one form which I am using for data entry. Now in that I have some TextBoxes like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?

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.