I am making a program that deals with basic algebraic functions. The following function is meant to calculate the value of x given a certain value of y. The problem is that the answer can't be exact, so I need to figure out how to find the closest number. I thought rounding would work, but it doesn't.

Code:
Private Sub cmdX_Click()
    Dim math As New clsMathParser
    Dim x As Single
    
    If lstEqu.Text = vbNullString Then
        MsgBox "You need to select an equation from the list.", vbCritical
        Exit Sub
    End If
    
    math.StoreExpression lstEqu.Text
    For x = xmin To xmax Step 0.001
        If Round(math.Eval1(x), 3) = Val(txtY) Then
            txtX = x
            Exit For
        End If
    Next x
End Sub