Roll-Your-Own Decimal Entry Filter

Roll-Your-Own Decimal Entry Filter

Here’s an easy method for making sure your users enter only numeric data, and only one decimal point. First, place two Public procedures in a standard module. You can use Private procedures in a form if you’re only using it there, but you’ll lose easy portability for future projects.

The first procedure makes sure the decimal point is only entered once. The second procedure filters out all non-numeric characters except the decimal point:

 Public Sub DecCheck(Target As String, ByRef KeyStroke As _	Integer)	If InStr(Target, ".") And KeyStroke = 46 Then		KeyStroke = 0	End IfEnd SubPublic Sub NumCheck(ByRef KeyStroke As Integer)	If (KeyStroke < 48 Or KeyStroke > 57) And (KeyStroke _		<> 46 And KeyStroke <> 8) Then		KeyStroke = 0	End IfEnd Sub

Then invoke the code from your TextBox’s KeyPress event:

 Private Sub txtUnitPrice_KeyPress(KeyAscii As Integer)	DecCheck txtUnitPrice, KeyAscii	NumCheck KeyAsciiEnd Sub

One caveat: This code doesn’t prevent text characters from being pasted in via the clipboard.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular