Solved

check for numerical entry

Posted on 2014-01-15
4
185 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
Comment Utility
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
Comment Utility
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
Comment Utility
Is there a way to ask a specific Expert when it comes asking questions on experts exchange?
0
 
LVL 76

Expert Comment

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now