IsseY IsseY - 1 month ago 7
Vb.net Question

Function giving warning saying no return values

Function LoginPass() As Boolean
Dim LogPass As New waxClass
Dim Ldt As DataTable = LogPass.LoginPass(LCase(UserName_TextBox.Text),
LCase(UserPass_TextBox.Text))
If Ldt.Rows.Count > 0 Then

waxClass.LMUser = Ldt.Rows(0).Item("Username").ToString
'Utility.LMUserID = Ldt.Rows(0).Item("UserID").ToString
Return True
End If
End Function


When I try to use the above function it gives a warning saying:


Function 'LoginPass' doesn't return a value on all code
paths. Are you missing a 'Return' statement?

Answer

Your function requires a Boolean return value.

You do not have a return value if Ldt.Rows.Count <= 0, so that is where the warning is coming from. Add and Else Return False and you should be fine.

If Ldt.Rows.Count > 0 Then
   waxClass.LMUser = Ldt.Rows(0).Item("Username").ToString
   'Utility.LMUserID = Ldt.Rows(0).Item("UserID").ToString
   Return True
Else
   Return False
End If