Reputation: 984
Is there a way to deactivate the following behavior of the IDE? This is very silly and you don't see this error at once. Hopy my comments in the coding explain it well.
As you see both lines return different things:
Faulty Line (Returns "false" because it addresses the return value of the function I am in)
If HasIpAddress Then
Correct Line (Adresses the function with an other signature):
If HasIpAddress() Then
Coding:
Public Shared Function HasIpAddress(ByVal p_WaitTimeInSeconds As Integer) As Boolean
Dim dEnd As Date = Date.Now.AddSeconds(p_WaitTimeInSeconds)
While dEnd > Date.Now
If HasIpAddress Then ' THIS is the faulty line.
' If HasIpAddress() Then ' THIS line would work, because of the "()"
' it addresses the function without parameters and not
' the return-value of the current function I am in.
Return True
End If
System.Threading.Thread.Sleep(100)
End While
Return False
End Function
Public Shared Function HasIpAddress() As Boolean
With System.Net.IPAddress.Parse(NetworkTools.GetMyIpAddress())
...Check for Loopbacks, Any, None etc...
End While
Return True
End Function
Upvotes: 0
Views: 40
Reputation: 545588
You cannot change this behaviour, it’s a non-configurable part of the language (unlike, say, Option Strict
). So there’s no general way for avoiding this pitfall other than training yourself to always put ()
behind function calls, even if the function has no argument, and hoping that muscle memory will kick in at some point.
Upvotes: 3