Home All Groups Group Topic Archive Search About

Function doesn't return a value on all code paths

Author
2 Aug 2006 3:13 PM
a
I have been cleaning up somebody else's code in Vs2005 .net 2.0

There wer lots of these code pat errors because of unitialized variables in
functions with Conditionals -  that may or may not be set . These I have
cleaned up ok.

But I have a few like this one below.

The error is   Function BindData doesn't return a value on all code paths
But I only see one code path.  What am I missing?

Thanks

Bill

Private Function BindData(ByVal count As Integer, ByVal custID As Integer,
ByVal tempID As Integer, ByVal groupID As Integer)

cmd = New SqlCommand("stp_getPreparedMessages", con)

da.SelectCommand = cmd

da.SelectCommand.CommandType = CommandType.StoredProcedure

da.SelectCommand.parameters.addwithvalue("@int_rCount", pSize)

da.SelectCommand.parameters.addwithvalue("@int_UserGroupId", groupID)

da.SelectCommand.parameters.addwithvalue("@int_CustomerID", custID)

da.SelectCommand.parameters.addwithvalue("@int_UserIdAdd",
Session("userID"))

da.SelectCommand.parameters.addwithvalue("@sint_AccessLevel",
Session("accessLevel"))

da.SelectCommand.parameters.addwithvalue("@int_tempid", tempID)

da.SelectCommand.parameters.addwithvalue("@int_pageCount",
SqlDbType.Int).Direction = ParameterDirection.Output

da.Fill(ds, "tblPrepMsgs")

pCount = da.SelectCommand.Parameters("@int_pageCount").Value

dgPreparedMsgs.DataSource = ds.Tables("tblPrepMsgs")

dgPreparedMsgs.DataBind()

End Function

Author
2 Aug 2006 5:40 PM
md
From what I see, you're not returning any value at all. Also, if you have
Option strict on full it will complain (as a warning I think) that you don't
specify a type for the function.

Matt


Show quoteHide quote
"a" <a*@ss.com> wrote in message
news:bi3Ag.1186$Qz2.689@tornado.tampabay.rr.com...
>I have been cleaning up somebody else's code in Vs2005 .net 2.0
>
> There wer lots of these code pat errors because of unitialized variables
> in functions with Conditionals -  that may or may not be set . These I
> have cleaned up ok.
>
> But I have a few like this one below.
>
> The error is   Function BindData doesn't return a value on all code paths
> But I only see one code path.  What am I missing?
>
> Thanks
>
> Bill
>
> Private Function BindData(ByVal count As Integer, ByVal custID As Integer,
> ByVal tempID As Integer, ByVal groupID As Integer)
>
> cmd = New SqlCommand("stp_getPreparedMessages", con)
>
> da.SelectCommand = cmd
>
> da.SelectCommand.CommandType = CommandType.StoredProcedure
>
> da.SelectCommand.parameters.addwithvalue("@int_rCount", pSize)
>
> da.SelectCommand.parameters.addwithvalue("@int_UserGroupId", groupID)
>
> da.SelectCommand.parameters.addwithvalue("@int_CustomerID", custID)
>
> da.SelectCommand.parameters.addwithvalue("@int_UserIdAdd",
> Session("userID"))
>
> da.SelectCommand.parameters.addwithvalue("@sint_AccessLevel",
> Session("accessLevel"))
>
> da.SelectCommand.parameters.addwithvalue("@int_tempid", tempID)
>
> da.SelectCommand.parameters.addwithvalue("@int_pageCount",
> SqlDbType.Int).Direction = ParameterDirection.Output
>
> da.Fill(ds, "tblPrepMsgs")
>
> pCount = da.SelectCommand.Parameters("@int_pageCount").Value
>
> dgPreparedMsgs.DataSource = ds.Tables("tblPrepMsgs")
>
> dgPreparedMsgs.DataBind()
>
> End Function
>
>
Author
2 Aug 2006 5:49 PM
Kerry Moorman
a,

It looks like this function should really be a subprocedure.

Kerry Moorman


Show quoteHide quote
"a" wrote:

> I have been cleaning up somebody else's code in Vs2005 .net 2.0
>
> There wer lots of these code pat errors because of unitialized variables in
> functions with Conditionals -  that may or may not be set . These I have
> cleaned up ok.
>
> But I have a few like this one below.
>
> The error is   Function BindData doesn't return a value on all code paths
> But I only see one code path.  What am I missing?
>
> Thanks
>
> Bill
>
> Private Function BindData(ByVal count As Integer, ByVal custID As Integer,
> ByVal tempID As Integer, ByVal groupID As Integer)
>
> cmd = New SqlCommand("stp_getPreparedMessages", con)
>
> da.SelectCommand = cmd
>
> da.SelectCommand.CommandType = CommandType.StoredProcedure
>
> da.SelectCommand.parameters.addwithvalue("@int_rCount", pSize)
>
> da.SelectCommand.parameters.addwithvalue("@int_UserGroupId", groupID)
>
> da.SelectCommand.parameters.addwithvalue("@int_CustomerID", custID)
>
> da.SelectCommand.parameters.addwithvalue("@int_UserIdAdd",
> Session("userID"))
>
> da.SelectCommand.parameters.addwithvalue("@sint_AccessLevel",
> Session("accessLevel"))
>
> da.SelectCommand.parameters.addwithvalue("@int_tempid", tempID)
>
> da.SelectCommand.parameters.addwithvalue("@int_pageCount",
> SqlDbType.Int).Direction = ParameterDirection.Output
>
> da.Fill(ds, "tblPrepMsgs")
>
> pCount = da.SelectCommand.Parameters("@int_pageCount").Value
>
> dgPreparedMsgs.DataSource = ds.Tables("tblPrepMsgs")
>
> dgPreparedMsgs.DataBind()
>
> End Function
>
>
>
Author
2 Aug 2006 5:58 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"a" <a*@ss.com> schrieb:
> The error is   Function BindData doesn't return a value on all code paths
> But I only see one code path.  What am I missing?
>
> Private Function BindData(ByVal count As Integer, ByVal custID As Integer,
> ByVal tempID As Integer, ByVal groupID As Integer)
>
> cmd = New SqlCommand("stp_getPreparedMessages", con)
>
> da.SelectCommand = cmd
>
> da.SelectCommand.CommandType = CommandType.StoredProcedure
>
> da.SelectCommand.parameters.addwithvalue("@int_rCount", pSize)
>
> da.SelectCommand.parameters.addwithvalue("@int_UserGroupId", groupID)
>
> da.SelectCommand.parameters.addwithvalue("@int_CustomerID", custID)
>
> da.SelectCommand.parameters.addwithvalue("@int_UserIdAdd",
> Session("userID"))
>
> da.SelectCommand.parameters.addwithvalue("@sint_AccessLevel",
> Session("accessLevel"))
>
> da.SelectCommand.parameters.addwithvalue("@int_tempid", tempID)
>
> da.SelectCommand.parameters.addwithvalue("@int_pageCount",
> SqlDbType.Int).Direction = ParameterDirection.Output
>
> da.Fill(ds, "tblPrepMsgs")
>
> pCount = da.SelectCommand.Parameters("@int_pageCount").Value
>
> dgPreparedMsgs.DataSource = ds.Tables("tblPrepMsgs")
>
> dgPreparedMsgs.DataBind()
>
> End Function

The function neither contains a 'Return <value>' statement nor does it
contain an assignment to the function name.  Thus you may want to replace
the 'Function' with 'Sub'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
4 Aug 2006 7:44 AM
GhostInAK
Hello a,

You could instead create a collection that disallowed adding non-unique values.

Public Class UniqueStringList
    Inherits List(Of String)


    Public Shadows Sub Add(ByVal tValue As String)

        If Not Me.Contains(tValue) Then
            MyBase.Add(tValue)
        End If

    End Sub

End Class

-Boo

Show quoteHide quote
> I have been cleaning up somebody else's code in Vs2005 .net 2.0
>
> There wer lots of these code pat errors because of unitialized
> variables in functions with Conditionals -  that may or may not be set
> . These I have cleaned up ok.
>
> But I have a few like this one below.
>
> The error is   Function BindData doesn't return a value on all code
> paths But I only see one code path.  What am I missing?
>
> Thanks
>
> Bill
>
> Private Function BindData(ByVal count As Integer, ByVal custID As
> Integer, ByVal tempID As Integer, ByVal groupID As Integer)
>
> cmd = New SqlCommand("stp_getPreparedMessages", con)
>
> da.SelectCommand = cmd
>
> da.SelectCommand.CommandType = CommandType.StoredProcedure
>
> da.SelectCommand.parameters.addwithvalue("@int_rCount", pSize)
>
> da.SelectCommand.parameters.addwithvalue("@int_UserGroupId", groupID)
>
> da.SelectCommand.parameters.addwithvalue("@int_CustomerID", custID)
>
> da.SelectCommand.parameters.addwithvalue("@int_UserIdAdd",
> Session("userID"))
>
> da.SelectCommand.parameters.addwithvalue("@sint_AccessLevel",
> Session("accessLevel"))
>
> da.SelectCommand.parameters.addwithvalue("@int_tempid", tempID)
>
> da.SelectCommand.parameters.addwithvalue("@int_pageCount",
> SqlDbType.Int).Direction = ParameterDirection.Output
>
> da.Fill(ds, "tblPrepMsgs")
>
> pCount = da.SelectCommand.Parameters("@int_pageCount").Value
>
> dgPreparedMsgs.DataSource = ds.Tables("tblPrepMsgs")
>
> dgPreparedMsgs.DataBind()
>
> End Function
>