Solved

check for numerical entry

Posted on 2014-01-15
4
190 Views
Last Modified: 2014-01-15
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
Comment
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
  • Learn & ask questions
  • 3
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
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

Open in new window

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 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

Open in new window

0
 

Author Closing Comment

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

Expert Comment

by:GrahamSkan
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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
Course of the Month10 days, 21 hours left to enroll

628 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