Please help with this function code!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Please help with this function code!

  1. #1
    Ray Wilson Guest

    Please help with this function code!


    Hello everybody. I'm still stuck on this program part:

    Sub practice()

    'define variables
    Dim month, quota, days, result As String

    'getting input
    quota = InputBox("What is the quota?")
    days = InputBox("How many days off?")


    'calculations and function

    month = Application.InputBox(prompt:="Please enter the month of the
    credit", Type:=1)
    MsgBox ("The number of calendar days in " & calendar(month) & " is" &
    calendar(month))
    End Sub


    'function

    Function calendar(days)
    calendar = ("23")
    calendar = ("20")
    calendar = ("22")
    End Function

    I basically want to have the user enter the month, and then the program will
    lookup the function to find out how many (working) days are in that specific
    month. (I have only put in January-March for easiness sake). Then I want
    the output to say "Number of days in JANUARY is 23".

    I'm not doing it right because it doesn't work. Any ideas? What am I doing
    wrong?

    Thanks,

    Ray Wilson


  2. #2
    Dean Earley Guest

    Re: Please help with this function code!

    It is probably best if you calculated the working days, as it changes every year.



    --
    Dean Earley (dean.earley@icode.co.uk)
    Assistant Developer

    iCode Systems
    "Ray Wilson" <zimabud@hotmail.com> wrote in message news:3acc8fc2$1@news.devx.com...
    >
    > Hello everybody. I'm still stuck on this program part:
    >
    > Sub practice()
    >
    > 'define variables
    > Dim month, quota, days, result As String
    >
    > 'getting input
    > quota = InputBox("What is the quota?")
    > days = InputBox("How many days off?")
    >
    >
    > 'calculations and function
    >
    > month = Application.InputBox(prompt:="Please enter the month of the
    > credit", Type:=1)
    > MsgBox ("The number of calendar days in " & calendar(month) & " is" &
    > calendar(month))
    > End Sub
    >
    >
    > 'function
    >
    > Function calendar(days)
    > calendar = ("23")
    > calendar = ("20")
    > calendar = ("22")
    > End Function
    >
    > I basically want to have the user enter the month, and then the program will
    > lookup the function to find out how many (working) days are in that specific
    > month. (I have only put in January-March for easiness sake). Then I want
    > the output to say "Number of days in JANUARY is 23".
    >
    > I'm not doing it right because it doesn't work. Any ideas? What am I doing
    > wrong?
    >
    > Thanks,
    >
    > Ray Wilson
    >




  3. #3
    Ray Wilson Guest

    Re: Please help with this function code!


    True. However this is for this year alone...so next year I will alter it accordingly....assuming
    I can make the darn thing work!

    Ray

    "Dean Earley" <dean.earley@icode.co.uk> wrote:
    >It is probably best if you calculated the working days, as it changes every

    year.
    >
    >
    >
    >--
    >Dean Earley (dean.earley@icode.co.uk)
    >Assistant Developer
    >
    >iCode Systems
    >"Ray Wilson" <zimabud@hotmail.com> wrote in message news:3acc8fc2$1@news.devx.com...
    >>
    >> Hello everybody. I'm still stuck on this program part:
    >>
    >> Sub practice()
    >>
    >> 'define variables
    >> Dim month, quota, days, result As String
    >>
    >> 'getting input
    >> quota = InputBox("What is the quota?")
    >> days = InputBox("How many days off?")
    >>
    >>
    >> 'calculations and function
    >>
    >> month = Application.InputBox(prompt:="Please enter the month of the
    >> credit", Type:=1)
    >> MsgBox ("The number of calendar days in " & calendar(month) & " is"

    &
    >> calendar(month))
    >> End Sub
    >>
    >>
    >> 'function
    >>
    >> Function calendar(days)
    >> calendar = ("23")
    >> calendar = ("20")
    >> calendar = ("22")
    >> End Function
    >>
    >> I basically want to have the user enter the month, and then the program

    will
    >> lookup the function to find out how many (working) days are in that specific
    >> month. (I have only put in January-March for easiness sake). Then I want
    >> the output to say "Number of days in JANUARY is 23".
    >>
    >> I'm not doing it right because it doesn't work. Any ideas? What am I doing
    >> wrong?
    >>
    >> Thanks,
    >>
    >> Ray Wilson
    >>

    >
    >



  4. #4
    Dean Earley Guest

    Re: Please help with this function code!

    Look up Select Case in the help files

    --
    Dean Earley (dean.earley@icode.co.uk)
    Assistant Developer

    iCode Systems
    "Ray Wilson" <zimabud@hotmail.com> wrote in message news:3acc9244$1@news.devx.com...
    >
    > True. However this is for this year alone...so next year I will alter it accordingly....assuming
    > I can make the darn thing work!
    >
    > Ray
    >
    > "Dean Earley" <dean.earley@icode.co.uk> wrote:
    > >It is probably best if you calculated the working days, as it changes every

    > year.
    > >
    > >
    > >
    > >--
    > >Dean Earley (dean.earley@icode.co.uk)
    > >Assistant Developer
    > >
    > >iCode Systems
    > >"Ray Wilson" <zimabud@hotmail.com> wrote in message news:3acc8fc2$1@news.devx.com...
    > >>
    > >> Hello everybody. I'm still stuck on this program part:
    > >>
    > >> Sub practice()
    > >>
    > >> 'define variables
    > >> Dim month, quota, days, result As String
    > >>
    > >> 'getting input
    > >> quota = InputBox("What is the quota?")
    > >> days = InputBox("How many days off?")
    > >>
    > >>
    > >> 'calculations and function
    > >>
    > >> month = Application.InputBox(prompt:="Please enter the month of the
    > >> credit", Type:=1)
    > >> MsgBox ("The number of calendar days in " & calendar(month) & " is"

    > &
    > >> calendar(month))
    > >> End Sub
    > >>
    > >>
    > >> 'function
    > >>
    > >> Function calendar(days)
    > >> calendar = ("23")
    > >> calendar = ("20")
    > >> calendar = ("22")
    > >> End Function
    > >>
    > >> I basically want to have the user enter the month, and then the program

    > will
    > >> lookup the function to find out how many (working) days are in that specific
    > >> month. (I have only put in January-March for easiness sake). Then I want
    > >> the output to say "Number of days in JANUARY is 23".
    > >>
    > >> I'm not doing it right because it doesn't work. Any ideas? What am I doing
    > >> wrong?
    > >>
    > >> Thanks,
    > >>
    > >> Ray Wilson
    > >>

    > >
    > >

    >




  5. #5
    Ray Wilson Guest

    Re: Please help with this function code!


    Select case doesn't output each individual case, though. Does it? If I understand
    correctly, that would output the data (# of days) but not the month for which
    that number corresponds. So could I use a function(month) similar to what
    I have in the code above along WITH a Select case? Is that possible?



    "Dean Earley" <dean.earley@icode.co.uk> wrote:
    >Look up Select Case in the help files
    >
    >--
    >Dean Earley (dean.earley@icode.co.uk)
    >Assistant Developer
    >
    >iCode Systems
    >"Ray Wilson" <zimabud@hotmail.com> wrote in message news:3acc9244$1@news.devx.com...
    >>
    >> True. However this is for this year alone...so next year I will alter

    it accordingly....assuming
    >> I can make the darn thing work!
    >>
    >> Ray
    >>
    >> "Dean Earley" <dean.earley@icode.co.uk> wrote:
    >> >It is probably best if you calculated the working days, as it changes

    every
    >> year.
    >> >
    >> >
    >> >
    >> >--
    >> >Dean Earley (dean.earley@icode.co.uk)
    >> >Assistant Developer
    >> >
    >> >iCode Systems
    >> >"Ray Wilson" <zimabud@hotmail.com> wrote in message news:3acc8fc2$1@news.devx.com...
    >> >>
    >> >> Hello everybody. I'm still stuck on this program part:
    >> >>
    >> >> Sub practice()
    >> >>
    >> >> 'define variables
    >> >> Dim month, quota, days, result As String
    >> >>
    >> >> 'getting input
    >> >> quota = InputBox("What is the quota?")
    >> >> days = InputBox("How many days off?")
    >> >>
    >> >>
    >> >> 'calculations and function
    >> >>
    >> >> month = Application.InputBox(prompt:="Please enter the month of the
    >> >> credit", Type:=1)
    >> >> MsgBox ("The number of calendar days in " & calendar(month) & " is"

    >> &
    >> >> calendar(month))
    >> >> End Sub
    >> >>
    >> >>
    >> >> 'function
    >> >>
    >> >> Function calendar(days)
    >> >> calendar = ("23")
    >> >> calendar = ("20")
    >> >> calendar = ("22")
    >> >> End Function
    >> >>
    >> >> I basically want to have the user enter the month, and then the program

    >> will
    >> >> lookup the function to find out how many (working) days are in that

    specific
    >> >> month. (I have only put in January-March for easiness sake). Then I

    want
    >> >> the output to say "Number of days in JANUARY is 23".
    >> >>
    >> >> I'm not doing it right because it doesn't work. Any ideas? What am

    I doing
    >> >> wrong?
    >> >>
    >> >> Thanks,
    >> >>
    >> >> Ray Wilson
    >> >>
    >> >
    >> >

    >>

    >
    >



  6. #6
    Arthur Wood Guest

    Re: Please help with this function code!


    Ray,
    What you are returning now is a Single Value, which happens to be the
    LAST value that you are assigning. I assume that what you THOUGHT you were
    getting was the value of the function that corresponded to the number (month)
    that you passed in?

    try it like this:

    Function calendar(Month as String) as Integer
    Select Case Month
    Case "JANUARY"
    Calendar = 23
    Case "FEBRUARY"
    Calendar = 20
    Case "MARCH"
    Calendar = 22
    end select

    End Function


    You would need to add Case lines like these for months "April" through "December"


    You would use this function like this:

    MsgBox "The number of calendar days in " & month & " is" & calendar(month),vbOkOnly
    "Ray Wilson" <zimabud@hotmail.com> wrote:
    >
    >Hello everybody. I'm still stuck on this program part:
    >
    > Sub practice()
    >
    > 'define variables
    > Dim month, quota, days, result As String
    >
    > 'getting input
    > quota = InputBox("What is the quota?")
    > days = InputBox("How many days off?")
    >
    >
    > 'calculations and function
    >
    > month = Application.InputBox(prompt:="Please enter the month of the


    >credit", Type:=1)
    > MsgBox ("The number of calendar days in " & calendar(month) & " is" &


    >calendar(month))
    > End Sub
    >
    >
    > 'function
    >
    > Function calendar(days)
    > calendar = ("23")
    > calendar = ("20")
    > calendar = ("22")
    > End Function
    >
    >I basically want to have the user enter the month, and then the program

    will
    >lookup the function to find out how many (working) days are in that specific
    >month. (I have only put in January-March for easiness sake). Then I want
    >the output to say "Number of days in JANUARY is 23".
    >
    >I'm not doing it right because it doesn't work. Any ideas? What am I doing
    >wrong?
    >
    >Thanks,
    >
    >Ray Wilson
    >



  7. #7
    Ray Wilson Guest

    Re: Please help with this function code!


    Arthur-

    Thank you. That is what I was trying to do. I knew that I would probably
    need to put the Select Case within the function itself, but I couldn't make
    it work right. I see what I was doing wrong.

    Thanks again.

    Ray Wilson


    "Arthur Wood" <Wooda@saic-trsc.com> wrote:
    >
    >Ray,
    > What you are returning now is a Single Value, which happens to be the
    >LAST value that you are assigning. I assume that what you THOUGHT you were
    >getting was the value of the function that corresponded to the number (month)
    >that you passed in?
    >
    >try it like this:
    >
    > Function calendar(Month as String) as Integer
    > Select Case Month
    > Case "JANUARY"
    > Calendar = 23
    > Case "FEBRUARY"
    > Calendar = 20
    > Case "MARCH"
    > Calendar = 22
    > end select
    >
    > End Function
    >
    >
    >You would need to add Case lines like these for months "April" through "December"
    >
    >
    >You would use this function like this:
    >
    >MsgBox "The number of calendar days in " & month & " is" & calendar(month),vbOkOnly
    >"Ray Wilson" <zimabud@hotmail.com> wrote:
    >>
    >>Hello everybody. I'm still stuck on this program part:
    >>
    >> Sub practice()
    >>
    >> 'define variables
    >> Dim month, quota, days, result As String
    >>
    >> 'getting input
    >> quota = InputBox("What is the quota?")
    >> days = InputBox("How many days off?")
    >>
    >>
    >> 'calculations and function
    >>
    >> month = Application.InputBox(prompt:="Please enter the month of the


    >
    >>credit", Type:=1)
    >> MsgBox ("The number of calendar days in " & calendar(month) & " is" &

    >
    >>calendar(month))
    >> End Sub
    >>
    >>
    >> 'function
    >>
    >> Function calendar(days)
    >> calendar = ("23")
    >> calendar = ("20")
    >> calendar = ("22")
    >> End Function
    >>
    >>I basically want to have the user enter the month, and then the program

    >will
    >>lookup the function to find out how many (working) days are in that specific
    >>month. (I have only put in January-March for easiness sake). Then I want
    >>the output to say "Number of days in JANUARY is 23".
    >>
    >>I'm not doing it right because it doesn't work. Any ideas? What am I doing
    >>wrong?
    >>
    >>Thanks,
    >>
    >>Ray Wilson
    >>

    >



  8. #8
    Luther Miller Guest

    Re: Please help with this function code!

    try and get the basics of s function down first:

    > Function calendar(days)
    > calendar = ("23")
    > calendar = ("20")
    > calendar = ("22")
    > End Function


    This function doesn't use it parameter, "days", for anything.
    Was it your intention to pass this parameter in and return another value
    based on the parameter?

    Function MonthAbbrev(ByVal viMonth As Integer) As String
    Select Case viMonth
    Case 1: MonthAbbrev = "Jan"
    Case 2: MonthAbbrev = "Feb"
    '... etc.
    Case 12: MonthAbbrev = "Dec"
    Case Else: MonthAbbrev = "Invalid Month!"
    End Select
    End Function



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center