Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

check for numerical entry

Posted on 2014-01-15
4
Medium Priority
?
192 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 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

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

879 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