A
A
aab1372020-03-16 12:13:21
Visual Basic
aab137, 2020-03-16 12:13:21

How to fix function argument type mismatch error?

There is a code

Function f(x As Single) As Single
    f = (100 - x) * (75 - x) * x
End Function
Sub program()
    eps = 0.00001
    l = 0 / 2
    r = 75 / 2
    Do While r - l > eps
    m = (r + l) / 2
    If (f(l) - f(l + eps)) * (f(m) - f(m + eps)) > 0 Then
        l = m
    Else
        r = m
    Loop
    Cells(1, 1).Value = (r + l) / 2
End Sub

Throws an error that it f(l)doesn't match the expected type.
How to fix?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BasiC2k, 2020-03-16
@BasiC2k

Check what the formula in function f returns and see if it matches the Single definition:


The Single value type is a 32-bit single-precision number with values ​​from negative 3.402823E38 to positive 3.402823E38, or positive or negative zero

If it does not match, then either a type cast or a type change will be required.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question