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.
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.