Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Identifying a function with multiple returns

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Resolved [RESOLVED] [2005] Identifying a function with multiple returns

    Lets say I have a function like the simple one I have posted below. When I call the function is there a way to call it specifically depending on which variable is given?

    Code:
        Function CalcMeals() As Decimal
            'Submit Var values to be used in the function
            decDays = CDec(cboDays.SelectedItem().ToString)
            decMeals = CDec(txtMeals.Text.ToString) * decDays
            decMealA = CDec(conMEALS * decDays)
            decMealCost = CDec(decMeals - decMealA)
            decMealSaved = CDec(decMealA - decMeals)
    
            'Determine whether to return what is owed or what is 
            'reimbursed.
            If decMeals > decMealA Then
                Return decMealCost
            ElseIf decMeals < decMealA Then
                Return decMealSaved
            End If
        End Function
    I can't really lay out what I mean, best way to say is that I want to direct the amount into different areas of the form depending on what variable is returned to me. If decMealSaved is returned I want it to be added in what is exempt and if decMealCost is returned then I want it to be added in what is owed to the company. I hope I'm getting my point across...

    Thanks if you can help.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Identifying a function with multiple returns

    That's a bit silly. Those two values are always going to have the same magnitude but a different sign. Just create one value and return it. If it's greater than zero then it means one thing and if its less than zero then it means the other.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: [2005] Identifying a function with multiple returns

    I am aware of that and it is easy to assume anything is silly when you have a firm grasp on what you are doing. I, on the other hand, am learning so what is silly to you could be a major dilemma to me.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width