Solved

Isnumeric

Posted on 2000-02-27
5
134 Views
Last Modified: 2010-05-02
I have a calculation field where there should only be a numeric input.  I suppose there should be an isnumeric verification on the change event but I'm not sure how to write it.
0
Comment
Question by:douglaskarr
[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
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
Vbmaster earned 10 total points
ID: 2562729
Here's a easy way to not allow the end user to enter any non-digits value into a textbox..

  Private Sub Text1_KeyPress(KeyAscii As Integer)

    If Not ((KeyAscii >= vbKey0) And (KeyAscii <= vbKey9)) Then
      KeyAscii = 0
    End If

  End Sub

This will only allow the keys 0 to 9.
0
 

Author Comment

by:douglaskarr
ID: 2562745
Thanks!
0
 

Author Comment

by:douglaskarr
ID: 2562750
Hold on... what about decimals?  ie: 5.1
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2562829
This would be a solution, it checks to make sure the input is numerical values and it will allow one decimal point (46 is the ascii code for the '.' character)...

  If Not ((KeyAscii >= vbKey0) And (KeyAscii <= vbKey9)) Then
    If Not ((KeyAscii = 46) And (InStr(Text1, ".") = 0)) Then
      KeyAscii = 0
    End If
  End If
0
 

Author Comment

by:douglaskarr
ID: 2562881
Thank-you very much...

Doug
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 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