Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim a As String = GetMsg("a")

''Other task

End Sub

Private Function GetMsg()
Return "5"
End Function


---------------------------------------

In above code why the compiler not giving any error for GetMsg function.Actually I am passing one parameter to GetMsg function but GetMsg function does not accept any function then why compiler not giving any error?
Posted

1 solution

This is a "feature" in VB.NET, legacy of VB. By default, option strict is off and it will not warn you about type mismatch. In this case, your GetMsg returns object which is implicitly cast into String.

Go to Project-> Properties -> Compile, find Options strict and set it to on. Then check the Warning configurations below and decide if you want certain types of notifications to be warning, error or ignored.

If this helps please take time to accept the solution. Thank you.
 
Share this answer
 
Comments
dinundmn 18-Dec-14 2:35am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900