Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

Isnumeric

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
douglaskarr
Asked:
douglaskarr
  • 3
  • 2
1 Solution
 
VbmasterCommented:
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
 
douglaskarrAuthor Commented:
Thanks!
0
 
douglaskarrAuthor Commented:
Hold on... what about decimals?  ie: 5.1
0
 
VbmasterCommented:
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
 
douglaskarrAuthor Commented:
Thank-you very much...

Doug
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now