I'm pretty sure that your intention is to evaluate Sin(x) where x is measured in degrees (if for no other reason than that evaluating at radians which are whole numbers other than 0 is quite rare), but the function Sin(x) works with radians. You can use the function Randians() to fix this:
Public Function first(ByVal x As Double) As Double
x = Application.Radians(x)
If (x + 1 < 0) Or (1 - 2 * Sin(x) < 0) Or Sqr(1 - 2 * Sin(x)) = 0 Then
first = "error"
Else
first = Sqr(x + 1) / Sqr(1 - 2 * Sin(x))
End If
End Function
Then, for example, first(7) evaluates to 1.218130941.
x? It is odd that you are not passingxas a parameter. Global variables are more often than not a design flaw.Sin(x)is 0.5 (30 degrees...?) thenSqr(1 - 2 * Sin(x))is zero and you cannot divide by zero.xmust be the parameter of the function. It looks like they translated it from Lithuanian (?) (where "pirma" means "first") and probably just dropped thexfrom the arguments.