473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

New to asking for help but HELP!!!!!

My taxes do not want to calculate. I have tried sub precedures, functions, loops, select cases, and if/else structures. Im out of things to try. HELP....

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3. Sub CalculateNetPay()
  4.  
  5. Dim gross As Decimal
  6. Dim fica As Decimal
  7. Dim netpay As Decimal
  8. Dim tax As Decimal
  9. gross = CalcGross(CDec(Me.rateTextBox.Text), CDec(Me.hoursTextBox.Text))
  10. grossTextBox.Text = gross.ToString
  11.  
  12. tax = calctaxes(gross)
  13. Me.taxTextBox.Text = tax.ToString
  14. fica = calcfica(gross)
  15. Me.ficaTextBox.Text = fica.ToString
  16.  
  17. netpay = gross - tax - fica
  18. netTextBox.Text = netpay.ToString
  19. End Sub
  20.  
  21. Function CalcGross(ByVal rate As Decimal, ByVal hours As Decimal) As Decimal
  22. Dim Pay As Decimal
  23. Dim OT As Decimal
  24. If hours <= 40 Then
  25.   Pay = rate * hours
  26.   OT = 0
  27. Else
  28.   Pay = rate * 40
  29.   OT = (hours - 40) * rate * 1.5
  30. End If
  31. Return (Pay + OT)
  32. End Function
  33.  
  34. Function calctaxes(ByVal locGross As Decimal) As Decimal
  35.  
  36. Dim taxes As Decimal
  37.  
  38. If singleButton.Checked Then
  39.   Call singleclick(taxes)
  40. End If
  41. If marriedButton.Checked Then
  42.   Call marriedclick(taxes)
  43. End If
  44.  
  45. Return locGross * taxes
  46. End Function
  47.  
  48. Private Function singleclick(ByVal locGross As Decimal) As Decimal
  49. Dim gross As Decimal
  50. Dim taxes As Decimal
  51. gross = CalcGross(CDec(Me.rateTextBox.Text), CDec(Me.hoursTextBox.Text))
  52.  
  53. If 0D < gross >= 51D = True Then
  54.   taxes = 0D
  55. ElseIf 51D < gross >= 552D Then
  56.   taxes = 0.15D
  57. ElseIf 552D < gross >= 1196D Then
  58.   taxes = 0.28D
  59. ElseIf 1196D < gross >= 2662D Then
  60.   taxes = 0.32D
  61. ElseIf 2662D < gross >= 5750D Then
  62.   taxes = 0.36D
  63. ElseIf gross >= 5750D Then
  64.   taxes = 0.396D
  65. End If
  66. Return taxes
  67. End Function
  68.  
  69. Private Function marriedclick(ByVal locGross As Decimal) As Decimal
  70. Dim gross As Decimal
  71. Dim taxes As Decimal
  72. gross = CalcGross(CDec(Me.rateTextBox.Text), CDec(Me.hoursTextBox.Text))
  73.  
  74. If 0 < gross >= 124.0 = True Then
  75.   taxes = 0.0
  76. ElseIf 124.0 < gross >= 960.0 Then
  77.   taxes = 0.15
  78. ElseIf 960.0 < gross >= 2023.0 Then
  79.   taxes = 0.28
  80. ElseIf 2023.0 < gross >= 3292.0 Then
  81.   taxes = 0.31
  82. ElseIf 3292.01 < gross >= 5809.0 Then
  83.   taxes = 0.36
  84. ElseIf gross >= 5809.0 Then
  85.   taxes = 0.396
  86. End If
  87. Return taxes
  88. End Function
  89.  
  90. Function calcfica(ByVal locGross As Decimal) As Decimal
  91. Return locGross * 0.0765
  92. End Function
  93.  
  94. Private Sub CalcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcButton.Click, marriedButton.Click, singleButton.Click
  95.  
  96. Call CalculateNetPay()
  97. End Sub
  98.  
  99. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  100.  
  101. End Sub
  102.  
  103. Private Sub singleButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles singleButton.CheckedChanged
  104.  
  105. End Sub
  106.  
  107. Private Sub marriedButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles marriedButton.CheckedChanged
  108.  
  109. End Sub
  110.  
  111. Private Sub hoursTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hoursTextBox.TextChanged
  112.  
  113. End Sub
  114.  
  115. Private Sub rateTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rateTextBox.TextChanged
  116.  
  117. End Sub
  118.  
  119. Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
  120.  
  121. End Sub
  122.  
  123. Private Sub taxTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles taxTextBox.TextChanged
  124.  
  125. End Sub
  126. End Class
Aug 4 '07 #1
1 1187
Killer42
8,435 Expert 8TB
I use VB6, so this may just be down to differences in your version. But it seems to me that this statement...
Expand|Select|Wrap|Line Numbers
  1. If 0D < gross >= 51D = True Then
may look good from a mathematical standpoint, but simply won't work.

As I said, keep in mind I may be completely wrong bout how the later versions of VB handle this stuff. But, if I'm right, VB will be doing this quite differently to the way it appears to read. Obviously what you mean is "if gross is between 0 and 51". But Vb would, in my opinion, handle this something like this... (I may have the order of precedence mixed up)
  • Test "0 < gross", returning True (-1) or False (0).
  • Test whether that result (0 or -1) is >= 51. Not possible, so obviously returns False (0).
  • Test whether the second result = True (-1).
So, as far as I can see, this test will always fail.

Hmm... now that I think further, I believe the logic is even more screwed up. It seems as though you are actually trying to test that gross is both greater than zero, and greaterthan/equal to 51. Which seems somewhat superfluous, wouldn't you say? It it's >= 51 then we know it's > 0.

Well, I'm not sure how much sense I'm making here, but I recommend you check the results of those IF tests very thoroughly. Perhaps you should consider rewriting using Select Case, something like this...

Expand|Select|Wrap|Line Numbers
  1. Select Case gross
  2.   Case 1 To 51
  3.     taxes = 0
  4.   Case 52 To 552
  5.     taxes = 0.15
  6.   Case 553 To 1196
  7.     taxes = 0.28
  8.   Case 1197 To 2662
  9.     taxes = 0.32
  10.   Case 2663 To 5750
  11.     taxes = 0.36
  12.   Case Else
  13.     taxes = 0.396
  14. End Select
Or if you prefer to stick with the IF structure, something like
Expand|Select|Wrap|Line Numbers
  1. If gross <= 51D Then
  2.   taxes = 0D
  3. ElseIf gross <= 552D Then
  4.   taxes = 0.15D
  5. ElseIf gross <= 1196D Then
  6.   taxes = 0.28D
  7. ElseIf gross <= 2662D Then
  8.   taxes = 0.32D
  9. ElseIf gross <= 5750D Then
  10.   taxes = 0.36D
  11. Else
  12.   taxes = 0.396D
  13. End If
Aug 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mike | last post by:
Hello All, I'm trying to deploy my windows-based application using crystal report. i package the setup by including the crystal report file, the exe file, and two merge modules for the crystal...
3
by: Mitchell Thomas | last post by:
I hope someone out there can solve my mysterious problem. I have tried everything imaginable, even paid $35 to Microsoft to help me, but they were not able to figure out this problem: Here is the...
0
by: chrisben | last post by:
Hi, Developing Env: .NET Studio in C#, windows 2000 target: a COM object used for excel user (RTD) I have no problem to compile and run the project in my machine. The excel is working great...
0
by: skip | last post by:
Manish> It does not work. I had already tried this earlier. Manish> Please suggest some other solutions. Manish> Also, I would like to see the stack from where the exception Manish> started. ...
0
by: lyynda | last post by:
Could someone please help me with a couple of answers to a class I am struggling thru!!!!!! I have to provide a truth table to find the truth value of A if Not (Z V not Y) AND Use...
2
by: accessnovice | last post by:
Hello All! I am new to programming in the MS Access environment and decided to join this community due to various problems I encountered in Access 2000 and 2003. I began a small project in Access...
2
by: rbelgane0 | last post by:
I should write a c++ program which determine if the line of text (string) forms a palindrome and print whether it is or not .I want to do this by do-while loop and also if statment inside the loop ,...
2
by: clouddragon | last post by:
Hi, i am in desperate need for any help regarding one of my assignments. I am to write a python program that lists the numbers that are composite from 1 to n(input) and write it to an external...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.