Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Question about textbox

Posted on 1999-06-27
6
Medium Priority
?
146 Views
Last Modified: 2010-05-02
How do i restrict the textbox so that it can enter 0-9, Period, and Press backspace only?? I have try to use thoe following code in the keypress event

If KeyAscii < Asc(".") Or KeyAscii > Asc("9") Then
        KeyAscii = 0
End If
0
Comment
Question by:clo1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:s_lavie
ID: 1520101
Use tthe same in the change event
0
 
LVL 2

Author Comment

by:clo1
ID: 1520102
Couldn't work !
0
 
LVL 10

Accepted Solution

by:
viktornet earned 0 total points
ID: 1520103
Place the following code in your Text Box's KeyPress event...

If KeyAscii <> 8 And KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then KeyAscii = 0

..-=ViKtOr=-..
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:KDivad
ID: 1520104
You should also add this to your change event:

Temp = Text1.Text
For I = Len(Text1.Text) To 1 Step -1
    TempA = Asc(Mid$(Text1.Text, I, 1))
    If TempA <> 46 And (TempA < 48 Or TempA > 57) Then
        Temp = Left$(Temp, I - 1) & Right$(Temp, Len(Temp) - I)
    End If
Next
Text1.Text = Temp

This will eliminate the possibility of a user pasting in characters you don't want.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1520105
Viktornet is close, but forgot to allow the "." in the box, use instead:

If KeyAscii <> 8 And KeyAscii <> 46 And (KeyAscii < 48 Or KeyAscii > 57) Then KeyAscii = 0
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1520106
oh, yeah... I forgot the need of "." for floating point numbers... oh well...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question