values match plus or minus a penny?

DeanRowe

Registered User.
Local time
Today, 21:40
Joined
Jan 26, 2007
Messages
142
Hi,

I have two text boxes that contain two number values, "test1" and "test2".
I currently use the following code to check that the values match:

Code:
if test1=test2 then
msgbox "Correct"
else
msgbox "incorrect

This works fine, however I want to be able to check they match "plus or minus a penny". For example:

Test1: 100.99
Test2: 100.98

Would produce a "correct" msg, but:

Test1: 100.99
Test2: 101.01

would produce a "incorrect" msg.

Does anyone know how to do this please as I can't find anything on google or here.

Thank you

Dean
 
Perhaps something like: -

Code:
    If Abs(Test1 - Test2) < 0.01 Then
        MsgBox "Correct"
    Else
        MsgBox "Incorrect"
    End If

Hope that helps.

Regards,
Chris.
 
Hi ChrisO,

Thanks for the response, and good idea, had to change the code slightly but it works perfectly:

Private Sub Command30_Click()
If Abs([test1] - [test2]) < 0.011 Then
MsgBox "Correct"
Else
MsgBox "Incorrect"
End If
End Sub

Cheers ChrisO

Dean
 
Glad it works.

Rather than extending the comparison data to 0.011 try using <= 0.01

It would more correctly cover the situation of the data being 0.0105

Regards,
Chris.
 

Users who are viewing this thread

Back
Top Bottom