Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# check for numerical entry

Posted on 2014-01-15
Medium Priority
191 Views
I have a vb6 form.  In one of the fields, I would like the user to enter the number of hours.  ie.  1, 1.5, 2, 2.5, etc...

How can I verify that they are entering a numerical entry with two decimal places max?
0
Question by:al4629740
[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
• 3

LVL 76

Expert Comment

ID: 39783964
You can check the text with this function:
``````Function Validate(strText As String) As Boolean
If IsNumeric(strText) Then
If UBound(Split(strText, ".")) = 1 Then
If Len(Split(strText, ".")(1)) > 2 Then
Exit Function
End If
End If
Validate = True
End If
End Function
``````
0

LVL 76

Accepted Solution

GrahamSkan earned 2000 total points
ID: 39783979
This shows one way to use the function:
``````Option Explicit

Private Sub Text1_LostFocus()
If Not Validate(Text1.Text) Then
MsgBox "Invalid entry"
End If
End Sub
Function Validate(strText As String) As Boolean
If IsNumeric(strText) Then
If UBound(Split(strText, ".")) = 1 Then
If Len(Split(strText, ".")(1)) > 2 Then
Exit Function
End If
End If
Validate = True
End If
End Function
``````
0

Author Closing Comment

ID: 39784052
Is there a way to ask a specific Expert when it comes asking questions on experts exchange?
0

LVL 76

Expert Comment

ID: 39784296
You can always ask in the question, but it is positively discouraged for good reason

The expert might not be around at the time, so the question could go unanswered. Also each question should be self-contained, and not rely on knowledge of the questioner's project that is not apparent in the question.
0

## Featured Post

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
###### Suggested Courses
Course of the Month11 days, 7 hours left to enroll