|
-
Mar 8th, 2000, 07:59 AM
#1
Thread Starter
Member
This function seems logical to me and works when I use a calculator - but in this program when I enter 90,000 The response shows tax as 13,500. I'm stuck on this one HELP!
Dim Income As Single, FicaTax As String
Option Explicit
Private Sub cmdCalculate_Click()
'obtain taxable income
Income = Val(InputBox("Enter taxable income:"))
Call DisplayTax
End Sub
Public Function TaxSingle() As Single
'calculate tax amount
Select Case TaxSingle
Case 0 To 25350
TaxSingle = 0.15 * Income
Case 25350 To 61400
TaxSingle = 3802.5 + (0.28 * (Income - 25350))
Case 61400 To 128100
TaxSingle = 13896.5 + (0.31 * (Income - 61400))
Case 128100 To 278450
TaxSingle = 34573.5 + (0.36 * (Income - 128100))
Case 278450
TaxSingle = 86699.5 + (0.396 * (Income - 278450))
End Select
End Function
Public Sub DisplayTax()
'display results
FicaTax = FormatCurrency(TaxSingle)
picResult.Cls
picResult.Print "Your FICA taxes based on the single rate of"
picResult.Print "taxable income are: "; FicaTax
End Sub
Private Sub cmdExit_Click()
End
End Sub
-
Mar 8th, 2000, 08:59 AM
#2
Addicted Member
Function
Try this, if you study it a bit I think that you will
get the hang of it:
Code:
Option Explicit
Dim Income As Single
Dim FicaTax As String
Dim TaxSingle As Single
Dim Perc As Single
Public Function GetTaxAmount(Income)
'calculate tax amount
Select Case Income
Case 0 To 25350
TaxSingle = 0.15 * Income
Case 25350 To 61400
TaxSingle = 3802.5 + (0.28 * (Income - 25350))
Case 61400 To 128100
TaxSingle = 13896.5 + (0.31 * (Income - 61400))
Case 128100 To 278450
TaxSingle = 34573.5 + (0.36 * (Income - 128100))
Case 278450
TaxSingle = 86699.5 + (0.396 * (Income - 278450))
End Select
End Function
Public Sub DisplayTax(TaxSingle)
'display results
FicaTax = TaxSingle
PicResult.Cls
PicResult.Print
Perc = (FicaTax / Income) * 100
PicResult.Print "Your FICA taxes based on the single rate of "; _
Format(Perc, "0.##") & "%"
PicResult.Print
PicResult.Print "taxable income are: "; Format(FicaTax, "$####.##")
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdCalculate_Click()
'obtain taxable income
Income = Val(InputBox("Enter taxable income:"))
'call the Functions/Subs either way
GetTaxAmount Income
Call DisplayTax(TaxSingle)
End Sub
-
Mar 8th, 2000, 09:16 AM
#3
Hyperactive Member
Look at the line "Select Case TaxSingle"
The variable TaxSingle is the name of your function (which is the variable you must SET in order to return a value).
Because when you start the function TaxSingle = 0
When you do "Select Case 0" you will ALWAYS get the first case being true.
Try this instead :
Code:
Option Explicit
Private Sub cmdCalculate_Click()
Dim Income as Single
'obtain taxable income
Income = Val(InputBox("Enter taxable income:"))
Call DisplayTax(Income)
End Sub
Private Sub DisplayTax(YourIncome as Single)
Dim FicaTax as Single
'display results
FicaTax = FormatCurrency(TaxSingle(YourIncome))
picResult.Cls
picResult.Print "Your FICA taxes based on the single rate of"
picResult.Print "taxable income are: "; FicaTax
End Sub
Public Function TaxSingle(MyIncome as Single) As Single
'calculate tax amount
Select Case MyIncome
Case 0 To 25350
TaxSingle = 0.15 * MyIncome
Case 25350 To 61400
TaxSingle = 3802.5 + (0.28 * (MyIncome - 25350))
Case 61400 To 128100
TaxSingle = 13896.5 + (0.31 * (MyIncome - 61400))
Case 128100 To 278450
TaxSingle = 34573.5 + (0.36 * (MyIncome - 128100))
Case 278450
TaxSingle = 86699.5 + (0.396 * (MyIncome - 278450))
End Select
End Function
Private Sub cmdExit_Click()
End
End Sub
Now the code wont always pick "Case 0 To 25350" but ALSO... each procedure will only look at variables it needs and will create those it wants to inside.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|