+ Reply to Thread
Results 1 to 4 of 4

Function that calls other functions

  1. #1
    Registered User
    Join Date
    12-15-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    11

    Function that calls other functions

    Hello everyone.

    I have an issue with calling a couple functions to return the desired value. What I am trying to do is get the type of material and its thickness and output time in seconds that sound will take to go through the material. Here is the code I have so far:


    Option Explicit


    Public Function GetSpeedOfSound(strMaterial As String) As Double
    Select Case LCase(strMaterial)
    Case "air"
    GetSpeedOfSound = 1126.1 'this case returns 1126.1 feet per second
    Case "water"
    GetSpeedOfSound = 4603.2 'this case returns 4603.2 feet per second
    Case "steel"
    GetSpeedOfSound = 20013.3 'this case returns 20013.3 feet per second
    Case "earth"
    GetSpeedOfSound = 22967.4 'this case returns 22967.4 feet per second
    End Select
    End Function

    Public Function GetInverseSpeed(strMaterial As String) As Double
    GetInverseSpeed = 1 / GetSpeedOfSound(strMaterial)
    End Function

    'purpose: get the type of material and its thickness and output time in seconds that sound will take to go through the material
    'param strMaterial: a string specifying the kind of material ("air", "water", "steel", "earth")_
    'param dblThick: a double specifying the amount of thickness of the material
    'returns: the number of seconds it takes for sound to go through thickness of the material
    Public Function GetSpeedThroughMaterial(strMaterial As String, dblThick As Double) As Double
    GetSpeedThroughMaterial = GetInverseSpeed(strMaterial) + GetSpeedOfSound(strMaterial)
    End Function


    The first two functions are working as they should, but I am not sure how to write the GetSpeedThroughMaterial function to return the desired calculation. All I know is that I should be able to accomplish this task with one line of code. I know I'm over thinking this, but for some reason it's just not clicking for me. Any help would greatly be appreciated. Thank you!

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,454

    Re: Function that calls other functions

    Correct me if I'm wrong, but shouldn't be a basic distance=rate*time calculation? thickness=rate*time --> time=thickness/rate. If this is correct, then it seems like total time should be either

    getspeedthroughmaterial=dblthick/getspeedofsound
    or
    getspeedthroughmaterial=dblthick*getinversespeed

    Is that what you are looking for?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

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

    Re: Function that calls other functions

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    12-15-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    11

    Re: Function that calls other functions

    Hello and thank you for the quick responses! MrShorty, sorry for the ambiguity of the code but the I believe the correct line of code was the first one you provided. Shg, thank you as well for spelling it for me so clearly . You guys rock and thanks again!

+ 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. reset function calls
    By kbka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2014, 09:00 AM
  2. Macro that calls List function
    By Lynn Porter in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-09-2013, 06:31 PM
  3. [SOLVED] Question about multiple function calls
    By Zerex71 in forum Excel General
    Replies: 2
    Last Post: 08-03-2006, 09:30 AM
  4. [SOLVED] Using ODBC function calls
    By Dave in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-15-2006, 10:40 AM
  5. [SOLVED] VBA: How to pass arrays in Function Calls?
    By Mac Lingo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2005, 04:09 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