Z
zymotic
Hi,
I'm just starting out with vb.net and programming in general. Can
someone tell me why that when i run this code and enter any number
into txtAnnualSal (other than 0) that i get an infinite loop
happening?
Private Sub btnCalcTax_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalcTax.Click
Dim annual_sal, income_tax As Double
annual_sal = CDbl(txtAnnualSal.Text)
Do While annual_sal <> 0
calculate_tax(annual_sal, income_tax)
txtTax.Text = FormatCurrency(income_tax)
annual_sal = CDbl(txtAnnualSal.Text)
Loop
MsgBox("Yearly salary must be greater than $0")
End Sub
Sub calculate_tax(ByVal annual_sal As Double, ByRef income_tax As
Double)
If annual_sal > 0 And annual_sal <= 5000 Then
income_tax = 0
End If
If annual_sal > 5000 And annual_sal <= 10000 Then
income_tax = annual_sal * 0.06
End If
If annual_sal > 10000 And annual_sal <= 20000 Then
income_tax = annual_sal * 0.15
End If
If annual_sal > 20000 And annual_sal <= 30000 Then
income_tax = annual_sal * 0.2
End If
If annual_sal > 30000 And annual_sal <= 40000 Then
income_tax = annual_sal * 0.25
End If
If annual_sal > 40000 Then
income_tax = annual_sal * 0.3
End If
End Sub
End Class
I'm just starting out with vb.net and programming in general. Can
someone tell me why that when i run this code and enter any number
into txtAnnualSal (other than 0) that i get an infinite loop
happening?
Private Sub btnCalcTax_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalcTax.Click
Dim annual_sal, income_tax As Double
annual_sal = CDbl(txtAnnualSal.Text)
Do While annual_sal <> 0
calculate_tax(annual_sal, income_tax)
txtTax.Text = FormatCurrency(income_tax)
annual_sal = CDbl(txtAnnualSal.Text)
Loop
MsgBox("Yearly salary must be greater than $0")
End Sub
Sub calculate_tax(ByVal annual_sal As Double, ByRef income_tax As
Double)
If annual_sal > 0 And annual_sal <= 5000 Then
income_tax = 0
End If
If annual_sal > 5000 And annual_sal <= 10000 Then
income_tax = annual_sal * 0.06
End If
If annual_sal > 10000 And annual_sal <= 20000 Then
income_tax = annual_sal * 0.15
End If
If annual_sal > 20000 And annual_sal <= 30000 Then
income_tax = annual_sal * 0.2
End If
If annual_sal > 30000 And annual_sal <= 40000 Then
income_tax = annual_sal * 0.25
End If
If annual_sal > 40000 Then
income_tax = annual_sal * 0.3
End If
End Sub
End Class