Function doesn't return a value on all code paths

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • a

    #1

    Function doesn't return a value on all code paths

    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 _getPreparedMes sages", con)

    da.SelectComman d = cmd

    da.SelectComman d.CommandType = CommandType.Sto redProcedure

    da.SelectComman d.parameters.ad dwithvalue("@in t_rCount", pSize)

    da.SelectComman d.parameters.ad dwithvalue("@in t_UserGroupId", groupID)

    da.SelectComman d.parameters.ad dwithvalue("@in t_CustomerID", custID)

    da.SelectComman d.parameters.ad dwithvalue("@in t_UserIdAdd",
    Session("userID "))

    da.SelectComman d.parameters.ad dwithvalue("@si nt_AccessLevel" ,
    Session("access Level"))

    da.SelectComman d.parameters.ad dwithvalue("@in t_tempid", tempID)

    da.SelectComman d.parameters.ad dwithvalue("@in t_pageCount",
    SqlDbType.Int). Direction = ParameterDirect ion.Output

    da.Fill(ds, "tblPrepMsg s")

    pCount = da.SelectComman d.Parameters("@ int_pageCount") .Value

    dgPreparedMsgs. DataSource = ds.Tables("tblP repMsgs")

    dgPreparedMsgs. DataBind()

    End Function


  • md

    #2
    Re: Function doesn't return a value on all code paths

    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


    "a" <aa@ss.comwro te in message
    news:bi3Ag.1186 $Qz2.689@tornad o.tampabay.rr.c om...
    >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 _getPreparedMes sages", con)
    >
    da.SelectComman d = cmd
    >
    da.SelectComman d.CommandType = CommandType.Sto redProcedure
    >
    da.SelectComman d.parameters.ad dwithvalue("@in t_rCount", pSize)
    >
    da.SelectComman d.parameters.ad dwithvalue("@in t_UserGroupId", groupID)
    >
    da.SelectComman d.parameters.ad dwithvalue("@in t_CustomerID", custID)
    >
    da.SelectComman d.parameters.ad dwithvalue("@in t_UserIdAdd",
    Session("userID "))
    >
    da.SelectComman d.parameters.ad dwithvalue("@si nt_AccessLevel" ,
    Session("access Level"))
    >
    da.SelectComman d.parameters.ad dwithvalue("@in t_tempid", tempID)
    >
    da.SelectComman d.parameters.ad dwithvalue("@in t_pageCount",
    SqlDbType.Int). Direction = ParameterDirect ion.Output
    >
    da.Fill(ds, "tblPrepMsg s")
    >
    pCount = da.SelectComman d.Parameters("@ int_pageCount") .Value
    >
    dgPreparedMsgs. DataSource = ds.Tables("tblP repMsgs")
    >
    dgPreparedMsgs. DataBind()
    >
    End Function
    >
    >

    Comment

    • Kerry Moorman

      #3
      RE: Function doesn't return a value on all code paths

      a,

      It looks like this function should really be a subprocedure.

      Kerry Moorman


      "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 _getPreparedMes sages", con)
      >
      da.SelectComman d = cmd
      >
      da.SelectComman d.CommandType = CommandType.Sto redProcedure
      >
      da.SelectComman d.parameters.ad dwithvalue("@in t_rCount", pSize)
      >
      da.SelectComman d.parameters.ad dwithvalue("@in t_UserGroupId", groupID)
      >
      da.SelectComman d.parameters.ad dwithvalue("@in t_CustomerID", custID)
      >
      da.SelectComman d.parameters.ad dwithvalue("@in t_UserIdAdd",
      Session("userID "))
      >
      da.SelectComman d.parameters.ad dwithvalue("@si nt_AccessLevel" ,
      Session("access Level"))
      >
      da.SelectComman d.parameters.ad dwithvalue("@in t_tempid", tempID)
      >
      da.SelectComman d.parameters.ad dwithvalue("@in t_pageCount",
      SqlDbType.Int). Direction = ParameterDirect ion.Output
      >
      da.Fill(ds, "tblPrepMsg s")
      >
      pCount = da.SelectComman d.Parameters("@ int_pageCount") .Value
      >
      dgPreparedMsgs. DataSource = ds.Tables("tblP repMsgs")
      >
      dgPreparedMsgs. DataBind()
      >
      End Function
      >
      >
      >

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Function doesn't return a value on all code paths

        "a" <aa@ss.comschri eb:
        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 _getPreparedMes sages", con)
        >
        da.SelectComman d = cmd
        >
        da.SelectComman d.CommandType = CommandType.Sto redProcedure
        >
        da.SelectComman d.parameters.ad dwithvalue("@in t_rCount", pSize)
        >
        da.SelectComman d.parameters.ad dwithvalue("@in t_UserGroupId", groupID)
        >
        da.SelectComman d.parameters.ad dwithvalue("@in t_CustomerID", custID)
        >
        da.SelectComman d.parameters.ad dwithvalue("@in t_UserIdAdd",
        Session("userID "))
        >
        da.SelectComman d.parameters.ad dwithvalue("@si nt_AccessLevel" ,
        Session("access Level"))
        >
        da.SelectComman d.parameters.ad dwithvalue("@in t_tempid", tempID)
        >
        da.SelectComman d.parameters.ad dwithvalue("@in t_pageCount",
        SqlDbType.Int). Direction = ParameterDirect ion.Output
        >
        da.Fill(ds, "tblPrepMsg s")
        >
        pCount = da.SelectComman d.Parameters("@ int_pageCount") .Value
        >
        dgPreparedMsgs. DataSource = ds.Tables("tblP repMsgs")
        >
        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/>

        Comment

        • GhostInAK

          #5
          Re: Function doesn't return a value on all code paths

          Hello a,

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

          Public Class UniqueStringLis t
          Inherits List(Of String)


          Public Shadows Sub Add(ByVal tValue As String)

          If Not Me.Contains(tVa lue) Then
          MyBase.Add(tVal ue)
          End If

          End Sub

          End Class

          -Boo
          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 _getPreparedMes sages", con)
          >
          da.SelectComman d = cmd
          >
          da.SelectComman d.CommandType = CommandType.Sto redProcedure
          >
          da.SelectComman d.parameters.ad dwithvalue("@in t_rCount", pSize)
          >
          da.SelectComman d.parameters.ad dwithvalue("@in t_UserGroupId", groupID)
          >
          da.SelectComman d.parameters.ad dwithvalue("@in t_CustomerID", custID)
          >
          da.SelectComman d.parameters.ad dwithvalue("@in t_UserIdAdd",
          Session("userID "))
          >
          da.SelectComman d.parameters.ad dwithvalue("@si nt_AccessLevel" ,
          Session("access Level"))
          >
          da.SelectComman d.parameters.ad dwithvalue("@in t_tempid", tempID)
          >
          da.SelectComman d.parameters.ad dwithvalue("@in t_pageCount",
          SqlDbType.Int). Direction = ParameterDirect ion.Output
          >
          da.Fill(ds, "tblPrepMsg s")
          >
          pCount = da.SelectComman d.Parameters("@ int_pageCount") .Value
          >
          dgPreparedMsgs. DataSource = ds.Tables("tblP repMsgs")
          >
          dgPreparedMsgs. DataBind()
          >
          End Function
          >

          Comment

          Working...