Results 1 to 17 of 17

VBA functions & Arguments

Threaded View

  1. #11
    Registered User
    Join Date
    11-03-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: VBA functions & Arguments

    Ok, so I am about to finalize my work and need help with the final step.

    So far I have 2 Function with a sub to test

    Private Sub test_getBaristaSalary()
    Dim InputYear As Integer
    
        InputYear = InputBox(Prompt:="How many years of Experience?")
        MsgBox Prompt:="Total Salary is $" & getBaristaSalary(Whatyearisit:=InputYear)
    
    End Sub
    
    Function getBaristaSalary(Whatyearisit As Integer)
    
      
        getBaristaSalary = Whatyearisit * 500 + 18000
        ' Annual Salary = $18000 + $500x(years as barista)
    End Function
    
    Function 2 is

    Private Sub test_getManagerSalary()
    Dim InputYearBarista As Integer
    Dim InputYearManager As Integer
    
        InputYearBarista = InputBox(Prompt:="Years of experience as Barista?")
        InputYearManager = InputBox(Prompt:="Years of experience as Manager?")
        MsgBox Prompt:="Total Salary is $" & getManagerSalary(BaristaYear:=InputYearBarista, ManagerYear:=InputYearManager)
    
    End Sub
    
    Function getManagerSalary(BaristaYear As Integer, ManagerYear As Integer)
      
        getManagerSalary = (BaristaYear * 500) + (ManagerYear * 1000) + 22000
        ' Annual Salary = $22000 + $500x(years as barista) + $1000x(years as a manager)
    End Function
    My third function needs to determine which of the first 2 functions will be used to calculate the equation based on the answer to InputYearManager. If the value of InputYearManager is anything besides 0 then I need to use the second function however if 0 is the answer then I need the first function used.

    So far I have this:
    [B]
    Private Sub test_getPredictedSalary()
    Dim InputYearBarista As Integer
    Dim InputYearManager As Integer
    
        InputYearManager = InputBox(Prompt:="Years of experience as Manager?")
        InputYearBarista = InputBox(Prompt:="Years of experience as Barista?")
        MsgBox Prompt:="Total Salary is $" & getPredictedSalary(BaristaYear:=InputYearBarista, ManagerYear:=InputYearManager)
    End Sub
    
    Function getPredictedSalary(BaristaYear As Integer, ManagerYear As Integer) As Double
    
    If InputYearManager >= 0 Then
        getPredictedSalary = getManagerSalary
    ElseIf InputYearManager = 0 Then
        getPredictedSalary = getBaristaSalary
    
    End If
    End Function
    
    
    ' Annual Salary = $22000 + $500x(years as barista) + $1000x(years as a manager)
    ' Annual Salary = $18000 + $500x(years as barista)
    



    When I run this I get a Complie Error: Argument not optional. Any suggestions?
    Last edited by Brad1951; 11-04-2012 at 04:25 PM.

Thread Information

Users Browsing this Thread

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

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