+ Reply to Thread
Results 1 to 11 of 11

Function within a function

  1. #1
    Registered User
    Join Date
    07-29-2014
    Location
    Arizona
    MS-Off Ver
    2013
    Posts
    7

    Function within a function

    I am trying to run a Case function within a Case function and I can't get it to work. The function deductible(DDD) runs ok by itself. When I try to run it from dedkind(dedtype) it won't run. I was told that it doesn't have a number to relate to but I don't understand. In dedkind(dedtype) the Case is in T18.

    function deductible(DDD) as double
    Select case DDD
    Case is > 25
    deductible = Range("T17")
    Case is >=5
    deductible = Range ("T17") -5
    Case is <5
    deductible = 0
    End select
    End function

    Function dedkind(dedtype) as double
    Select case dedtype
    Case is = "DDD"
    dedkind = deductible(DDD)
    Case is = "DDD10"
    Dedkind = 10
    Case is = "DDDIP"
    dedkind = 15
    End select
    End function

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: Function within a function


    Big, Big, Big, and so on …, Big mistake you did !

    In dedkind function put a breakpoint on line dedkind = deductible(DDD)
    and check what is the value of variable DDD ?

    Nothing 'cause undeclared / undefined variable ‼ So check logic …

    And you must follow forum rules and use code tags : edit your post !
    Last edited by Marc L; 07-29-2014 at 01:17 PM.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Function within a function

    Where are you calling the function(s) from?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    07-29-2014
    Location
    Arizona
    MS-Off Ver
    2013
    Posts
    7

    Re: Function within a function

    In cell AB15 I have =dedkind(t18). T18 has the type of deductible. In cell T17 I have a number that is the amount of deductible. I am new to this and don't understand what a breakpoint is. I think I understand about the undelcred variable but don't know how to correct it. Thanks

  5. #5
    Registered User
    Join Date
    07-29-2014
    Location
    Arizona
    MS-Off Ver
    2013
    Posts
    7

    Re: Function within a function

    In cell AB15 I have =dedkind(t18). T18 has the type of deductible. In cell T17 I have a number that is the amount of deductible. Thanks

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Function within a function

    Why two functions?

    I think it would make more sense to have one function that you pass two arguments to.

  7. #7
    Registered User
    Join Date
    07-29-2014
    Location
    Arizona
    MS-Off Ver
    2013
    Posts
    7

    Re: Function within a function

    I have about twenty types of deductibles and each one has various calculations. I am trying to get the first part working and then I will expand the code. Thanks

  8. #8
    Registered User
    Join Date
    07-29-2014
    Location
    Arizona
    MS-Off Ver
    2013
    Posts
    7

    Re: Function within a function

    I have tried and tried but can't get this to work. Can someone tell me what I am doing wrong and how to correct it. The function Deductible(DXS) runs on its own. When I call it from Dedkind(dedtype) it won't work. I was told I hadn't declared it and have tried but still can't get it to work. Thanks.

    Function Deductible(DXS) as double
    Select Case DXS
    Case is > 25
    Deductible = Range("T17")
    Case is >= 5
    Deductible = (Rang("T17") -5)
    Case is <5
    Deductible = 0
    End Select
    End Function


    Function Dedkind(dedtype) as Double
    Dim Deductible() as Double
    Select Case dedtype
    Case is "DXS"
    Dedkind=deductible(DXS)
    Case is "DXT"
    Dedkind=10
    Case is XST"
    Dedkind=15
    End Select
    End Function

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Function within a function


    Again, you must use code tags, edit your post !

    In the line Dedkind=deductible(DXS) what DXS is supposed to be ?‼‼

    Just check logic … Verify variables value by following code via F8 key …
    Last edited by Marc L; 07-30-2014 at 03:51 PM.

  10. #10
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: Function within a function

    Please Login or Register  to view this content.
    The naming conflict will create some kind of problem.

    The variable passed to the deductible function is an undeclared variable, so it will be passed as an empty variant. When compared to an integer, it will either error, or be treated as the value 0 (0<5, so it will always return whatever you have for this case). You need to assign some kind of value to this variable (or pass it to deductible as a constant).
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Function within a function

    A function should always receive all of its arguments:

    Please Login or Register  to view this content.
    =Deduction(T18, T17)
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  2. index function error using match function to get data from a cell in an array
    By mabildgaard in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-17-2013, 02:21 AM
  3. [SOLVED] Using Offset function as the array in the PercentRank function is giving wrong result
    By Bobneil in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-06-2013, 09:29 PM
  4. Replies: 1
    Last Post: 03-21-2012, 11:22 AM
  5. Replies: 2
    Last Post: 03-20-2009, 01:29 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1