Solved

check for numerical entry

Posted on 2014-01-15
4
188 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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
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…
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…

828 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