By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

in textbox only number should enter

P: 21
In textbox i want to enter only number not any alphabates. please tell how i code that
Sep 8 '07 #1
Share this Question
Share on Google+
17 Replies


gits
Expert Mod 5K+
P: 5,270
hi ...

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

kind regards
Sep 9 '07 #2

Expert 10K+
P: 11,448
... and what language?

kind regards,

Jos
Sep 9 '07 #3

P: 21
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

P: 21
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

P: 21
... 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

10K+
P: 13,264
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
100+
P: 180
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

P: 21
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
100+
P: 180
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
Expert 100+
P: 1,445
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
100+
P: 1,977
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
Expert 100+
P: 1,445
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
100+
P: 1,977
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
Expert 100+
P: 1,445
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
100+
P: 1,977
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

Expert 5K+
P: 8,434
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

P: 21
I really very thank my problem solved
Sep 12 '07 #18

Post your reply

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