G
Guest
I know that this is just a warning message, but I wonder why the IDE flags
the first function with a warning, but not the second one. The warning
message is :
Function 'GetView' doesn't return a value on all code paths. A null
reference exception could occur at run time when the result is used.
Here is the code:
______________________________________________________________________
Public Class SearchMgr
Public Enum SearchMgrTables
Subscriptions
Contacts
Invoices
End Enum
..
..
..
Public Function GetView(ByVal table As SearchMgrTables, ByVal colname As
String) As DataView
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr Is Nothing Then
SubSrchMgr = New SubSearchViewMgr
End If
Return SubSrchMgr.GetView(colname)
Case SearchMgrTables.Contacts
If ContactSrchMgr Is Nothing Then
ContactSrchMgr = New ContactSearchViewMgr
End If
Return ContactSrchMgr.GetView(colname)
Case SearchMgrTables.Invoices
If OpenInvSrchMgr Is Nothing Then
OpenInvSrchMgr = New OpenInvSearchViewMgr
End If
Return OpenInvSrchMgr.GetView(colname)
End Select
End Function
Public Function Seek(ByVal table As SearchMgrTables, ByVal val As
String) As Integer
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr IsNot Nothing Then
Return Search(SubSrchMgr.CurrentView, val,
SubSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Contacts
If ContactSrchMgr IsNot Nothing Then
Return Search(ContactSrchMgr.CurrentView, val,
ContactSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Invoices
If OpenInvSrchMgr IsNot Nothing Then
Return Search(OpenInvSrchMgr.CurrentView, val,
OpenInvSrchMgr.CurrentColumnNum)
End If
End Select
'Throw New ArgumentException("You must select a view before you can
seek.")
End Function
I commented out the "Throw" statement to make the Seek function look
identical to the GetView function. But the IDE only complains about the
GetView function.
Any Ideas?
Terry
the first function with a warning, but not the second one. The warning
message is :
Function 'GetView' doesn't return a value on all code paths. A null
reference exception could occur at run time when the result is used.
Here is the code:
______________________________________________________________________
Public Class SearchMgr
Public Enum SearchMgrTables
Subscriptions
Contacts
Invoices
End Enum
..
..
..
Public Function GetView(ByVal table As SearchMgrTables, ByVal colname As
String) As DataView
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr Is Nothing Then
SubSrchMgr = New SubSearchViewMgr
End If
Return SubSrchMgr.GetView(colname)
Case SearchMgrTables.Contacts
If ContactSrchMgr Is Nothing Then
ContactSrchMgr = New ContactSearchViewMgr
End If
Return ContactSrchMgr.GetView(colname)
Case SearchMgrTables.Invoices
If OpenInvSrchMgr Is Nothing Then
OpenInvSrchMgr = New OpenInvSearchViewMgr
End If
Return OpenInvSrchMgr.GetView(colname)
End Select
End Function
Public Function Seek(ByVal table As SearchMgrTables, ByVal val As
String) As Integer
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr IsNot Nothing Then
Return Search(SubSrchMgr.CurrentView, val,
SubSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Contacts
If ContactSrchMgr IsNot Nothing Then
Return Search(ContactSrchMgr.CurrentView, val,
ContactSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Invoices
If OpenInvSrchMgr IsNot Nothing Then
Return Search(OpenInvSrchMgr.CurrentView, val,
OpenInvSrchMgr.CurrentColumnNum)
End If
End Select
'Throw New ArgumentException("You must select a view before you can
seek.")
End Function
I commented out the "Throw" statement to make the Seek function look
identical to the GetView function. But the IDE only complains about the
GetView function.
Any Ideas?
Terry