Function return value

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

    Function return value

    This is my first function in Visual and I'm having a simple syntax
    syntax issue that I'm hoping someone can help correct for me.

    I have a function
    Public Function Sub_Agg_Embedde d_Catgeories(Pa ss_Report_Type_ Desc As
    String, other variables, ....) As Integer

    I call it with the statement
    intReturn = Sub_Agg_Embedde d_Gender(Pass_R eport_Type_Desc , other
    variables)


    when the function has completed, I want to Return a variable which is
    called Sum_Points and have it assigned to intReturn.

    Seems simple enough... At the end of the function I place
    Return(Sum_Poin t) or Return Sum_Points ... and I get a syntax error of
    "Expected end of statement"

    What is the proper syntax for returning a single Integer to the
    calling function in Visual?

    Thanks in advance for your help.
    BlueDolphin
  • Salad

    #2
    Re: Function return value

    bluedolphin wrote:
    [color=blue]
    > This is my first function in Visual and I'm having a simple syntax
    > syntax issue that I'm hoping someone can help correct for me.
    >
    > I have a function
    > Public Function Sub_Agg_Embedde d_Catgeories(Pa ss_Report_Type_ Desc As
    > String, other variables, ....) As Integer
    >
    > I call it with the statement
    > intReturn = Sub_Agg_Embedde d_Gender(Pass_R eport_Type_Desc , other
    > variables)
    >
    >
    > when the function has completed, I want to Return a variable which is
    > called Sum_Points and have it assigned to intReturn.
    >
    > Seems simple enough... At the end of the function I place
    > Return(Sum_Poin t) or Return Sum_Points ... and I get a syntax error of
    > "Expected end of statement"
    >
    > What is the proper syntax for returning a single Integer to the
    > calling function in Visual?
    >
    > Thanks in advance for your help.
    > BlueDolphin[/color]

    Private Function AddIT(I As Integer, J As Integer) As Integer
    AddIt = I + J
    End Function

    Dim var As Variant
    var = AddIt(1,2)
    Msgbox Var

    Assign the return value the name of the function.

    Comment

    • bluedolphin

      #3
      Re: Function return value

      I found the answer... Thanks though ...

      In case anyone has the same question, the syntax is

      Sub_Agg_Embedde d_Catgeories = Sum_Point

      Comment

      • Rob Parker

        #4
        Re: Function return value

        bcaponet@jeffco .k12.co.us (bluedolphin) wrote in message news:<3774cb79. 0410071025.6d97 50e9@posting.go ogle.com>...[color=blue]
        > This is my first function in Visual and I'm having a simple syntax
        > syntax issue that I'm hoping someone can help correct for me.
        >
        > I have a function
        > Public Function Sub_Agg_Embedde d_Catgeories(Pa ss_Report_Type_ Desc As
        > String, other variables, ....) As Integer
        >
        > I call it with the statement
        > intReturn = Sub_Agg_Embedde d_Gender(Pass_R eport_Type_Desc , other
        > variables)
        >
        >
        > when the function has completed, I want to Return a variable which is
        > called Sum_Points and have it assigned to intReturn.
        >
        > Seems simple enough... At the end of the function I place
        > Return(Sum_Poin t) or Return Sum_Points ... and I get a syntax error of
        > "Expected end of statement"
        >
        > What is the proper syntax for returning a single Integer to the
        > calling function in Visual?
        >
        > Thanks in advance for your help.
        > BlueDolphin[/color]

        Your call to your function, using

        intReturn = Sub_Agg_Embedde d_Gender(Pass_R eport_Type_Desc , other
        variables)

        is how it's done. Your problem is within the function itself. If you
        really want to return a variable called Sum_Point, then that's what
        your function must be named (and your calling statement will need to
        be changed), and within the function you must include the statement:

        Sum_Point = (the result of the operations you've conducted on the
        input variables)

        In your case, you are already assigning the function's return value to
        intReturn, but the function doesn't know what to return, since you
        aren't assigning the result of the operations to the function. All
        you need to do is include the statement:

        Sub_Agg_Embedde d_Gender = (the result of the operations you've
        conducted on the input variables)

        before the End Function line.

        Note: if the function could return several possible values (eg. the
        operations include IF statements), you would have several
        Sub_Agg_Embedde d_Gender = (something)
        statements, possible with an
        Exit Function
        statement after each, depending on the actual structure of your IF
        statements.

        HTH,

        Rob

        Comment

        • Pieter Linden

          #5
          Re: Function return value

          bcaponet@jeffco .k12.co.us (bluedolphin) wrote in message news:<3774cb79. 0410071025.6d97 50e9@posting.go ogle.com>...[color=blue]
          > This is my first function in Visual and I'm having a simple syntax
          > syntax issue that I'm hoping someone can help correct for me.
          >
          > I have a function
          > Public Function Sub_Agg_Embedde d_Catgeories(Pa ss_Report_Type_ Desc As
          > String, other variables, ....) As Integer
          >
          > I call it with the statement
          > intReturn = Sub_Agg_Embedde d_Gender(Pass_R eport_Type_Desc , other
          > variables)
          >
          >
          > when the function has completed, I want to Return a variable which is
          > called Sum_Points and have it assigned to intReturn.
          >
          > Seems simple enough... At the end of the function I place
          > Return(Sum_Poin t) or Return Sum_Points ... and I get a syntax error of
          > "Expected end of statement"
          >
          > What is the proper syntax for returning a single Integer to the
          > calling function in Visual?
          >
          > Thanks in advance for your help.
          > BlueDolphin[/color]


          if you want to assign the result of function call to intReturn, it's just:

          intReturn=SomeF unction(arg1, arg2,...)

          Oh, lemme guess... this looks a LOT like you're from the C/C++ world...

          Sub ShowValueSomewh ere()
          Dim intPutReturnVal ueHere As Integer
          Dim intUserValue as integer

          intUserValue=ci nt(Inputbox("Pl ease enter a number:"))
          '--calls the TimesFive function and assigns the result to intPut...
          intPutReturnVAl ueHere=TimesFiv e(intUserValue)

          End Sub
          Function TimesFive(byval intInput as integer) As Integer
          TimesFive=intIn put * 5
          End Function

          Comment

          Working...