Hello,
I am creating a program that will allow me to calculate taxes on a pay. Since the amounts deducted are not straight percentages, there are close to 5600 different options, based on the gross pay amount. I am wanting to make the program as versitile as possible, so I am hoping to be able to include as many of the options as I can. Using If....then or Select Case statements means a heck of a lot of code for each different deduction. Can anyone suggest a faster way?

Thanks in advance for the assistance!

Recommended Answers

All 4 Replies

Use arrays or collections. Maybe even dictionary might work in that.

But maybe a simple array will do (pseudo code):

Const TotalOptions = 5600
Dim GrossPay(TotalOptions) As Single
Dim Deduct(TotalOptions) As Single
' Fill arrays with proper values, GrossPay in increasing order and Deduct with matching index with GrossPay
GrossPay(1) = 500
Deduct(1) = 10
GrossPay(2) = 700
Deduct(2) = 13
.
.
GrossPay(5600) = 500000
Deduct(5600) = 15000

Now with given gross pay amount search matching "class" in arrays:

CurIndex = 1
For i = 1 To TotalOptions
  If ThisPay <= GrossPay(CurIndex) Then
    Exit For
  End If
Next i

and Deduct(CurIndex) is now the amount to deduct.

I did assume that you don't need any special logic, just calculation. You may also put GrossPay and Deduct values in a file and read them from a file.

what about defining a separate procedure / function for your required functionality

Thank you to both of your for your answers. I had considered arrays, but was trying to avoid having to type of the 5600 values, since there are 4 different deductions, and about the same number of possible deduction amounts for each, but I am not sure if I can avoid it. Thank you for your assistance.

debasisdas is right. make a function that will accept the percentage then calculate it inside the function according to the percentage given like i.e.

Private Function Calculate (percentage as Double) As Double
     Dim x As Integer
     Dim y As Integer

     Calculate = (x + y) * percentage
End Function

Note: Sample Only

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.