Val Function and Decimals

karmahum

Registered User.
Local time
Today, 03:46
Joined
Apr 29, 2002
Messages
53
Hello all.

I am trying to convert the contents of a textbox from a string to a number in order to test the input values. I am using the Val Function and it works great when the contents contain no decimals. However, as soon as decimals is entered, things go wrong.

Here is the code:

Private Sub Desired_Loss_Ratio_Exit(Cancel As Integer)
Dim Response As String
Dim dblValue As Double

dblValue = Val(Me.Desired_Loss_Ratio)

If dblValue <> 0 Then
If dblValue < -1 Or dblValue > 1 Then
Response = MsgBox("You entered an Desired Loss Ratio value of " & Me.Desired_Loss_Ratio & "." & vbCrLf & vbCrLf & _
"Are you sure this is the value you intended to enter?", vbYesNoCancel + vbInformation, _
"Verify Value")
If Response = vbYes Then
Exit Sub
ElseIf Response = vbNo Then
Me.Desired_Loss_Ratio.Value = 0
Cancel = True
ElseIf Response = vbCancel Then
Cancel = True
End If
End If
End If
End Sub

It appears that the Val function can not process decimals. For example, if the input is "1.02%", the val function returns 1.

Any ideas?

Thanks.
 
How about isnumeric validation...?

This may solve the problem just an ideal not sure if it applies to your train of thought....

Regards,
 
I got it...

It appears that the % sign at the end was messing things up. So, I just trimmed off the % sign and the Val Function does the rest.

Strange that the % would do that.

OK. Thanks.
 

Users who are viewing this thread

Back
Top Bottom