Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to make a small project in vb for employee income and tax calculator

Status
Not open for further replies.
i have t caculate it on annual basis and want to code it so that it can show the highest salary person and the lowest salary employee also so how can i do these two things too.
 
HI,

What application are you coding in?

This does not look like VBA.

What is this literal???
Code:
If salaryAmount >= [b]10600D[/b] The

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Please answer my specific questions.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
If salaryAmount >= 10600 The

you asking about abo tax of 25 percent.

 
What application are you coding in?
This is Visual Basic for APPLICATIONS, like Excel, Word, Outlook etc.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
VB is a LANGUAGE.

This forum is for VBA, not VB.

So you need to determine, what kind, like VB Net or VB version 6 or ??? Neither of these VBs are addressed in this forum.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
What APPLICATION are you coding your VBA in?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
just want to code a small application in exe...

You don't code in exe. An exe is a compiled executable. It's what is generated from code like VB.

That is NOT what happens with VBA! You do not generate an exe.

Again, what APPLICATION are you running in which you need to code VBA? Excel? Word? Outlook? Access?

Which one???

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thank you.

So what happens to your code when you, in the VBA Editor, try to Debug > Compile VBAProject

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I AM GETTING ERROR I AM USING THESE CODE MAY BE I AM WRONG IN CODING AS ITS INCOMPLETE ALSO CAN YOU CORRECT IT ACCORDING TO MY NEEDS PLEASE.

Private Sub CalculateDisplayAmounts(ByVal salary As Decimal)
Dim taxRate
 
Okay, but we need to establish some things.

Where is the source data for employees and salary located?

Do you have test data in a workbook that can be used to validate design and coding?

What procedure calls CalculateDisplayAmounts?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Additionally, if you could upload a version of your spreadsheet with dummy data, it might help as well.
 
So here's some VBA, using your original code, to get you started.
Code:
Private Sub CalculateDisplayAmounts(ByVal salary As Currency)
    Dim taxRate As Single
    Dim taxAmount As Currency
    Dim takeHomePay As Currency
    
    taxRate = GetTaxRate(salary)
    taxAmount = salary * taxRate
    takeHomePay = salary - taxAmount
'[b]What is the intent here? Seems that you might have a Form?
'So we need LOTS more information from your form here
'not some other code that you copied from.[/b]
    'taxRateLabel.Invoke(Sub(x) taxRateLabel.Text = FormatPercent(x), taxRate)
    'taxAmountLabel.Invoke(Sub(x) taxAmountLabel.Text = FormatCurrency(x), taxAmount)
    'takeHomeLabel.Invoke(Sub(x) takeHomeLabel.Text = FormatCurrency(x), takeHomePay)
End Sub

Private Function GetTaxRate(ByVal salaryAmount As Currency) As Single
    Select Case salaryAmount
        Case Is > 1000000
            GetTaxRate = 0.4
        Case Is > 600000
            GetTaxRate = 0.25
        Case Else
            GetTaxRate = 0.15   '[b]I don't know what rate less than 600000???[/b]
    End Select
End Function

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
So here's the code putting the results on Sheet1. Put the salary of interest in A2...
Code:
Sub testit()
    Dim salary As Currency
    
    salary = Sheet1.Cells(2, 1).Value
    CalculateDisplayAmounts salary
End Sub

Private Sub CalculateDisplayAmounts(ByVal salary As Currency)
    Dim taxRate As Single
    Dim taxAmount As Currency
    Dim takeHomePay As Currency
    
    taxRate = GetTaxRate(salary)
    taxAmount = salary * taxRate
    takeHomePay = salary - taxAmount
    
'[b]that is the intent here? Seems that you might have a Form?
'So we need LOTS more information[/b]
    'taxRateLabel.Invoke(Sub(x) taxRateLabel.Text = FormatPercent(x), taxRate)
    'taxAmountLabel.Invoke(Sub(x) taxAmountLabel.Text = FormatCurrency(x), taxAmount)
    'takeHomeLabel.Invoke(Sub(x) takeHomeLabel.Text = FormatCurrency(x), takeHomePay)
    
'here's your values on Sheet1
    With Sheet1
        .Cells(1, 1).Value = "Salary"
        .Cells(1, 2).Value = "Tax Rate"
        .Cells(1, 3).Value = "Tax Amount"
        .Cells(1, 4).Value = "Take Home Pay"
        
        .Cells(2, 2).Value = taxRate
        .Cells(2, 3).Value = taxAmount
        .Cells(2, 4).Value = takeHomePay
    End With
End Sub

Private Function GetTaxRate(ByVal salaryAmount As Currency) As Single
    Select Case salaryAmount
        Case Is > 1000000
            GetTaxRate = 0.4
        Case Is > 600000
            GetTaxRate = 0.25
        Case Else
            GetTaxRate = 0.15   '[b]I don't know what rate less than 600000???[/b]
    End Select
End Function


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top