Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
Dim strMoney As String
Dim dblMoney As Double
Dim dblTotal As Double
Dim arrDivisor() As Double = {1000.0, 100.0, 50.0, 20.0, 10.0, 5.0, 1.0, 0.25, 0.1, 0.05, 0.01}
Dim arrChangeType() As String = {"thousand dollar bills: ", "hundred dollar bills: ", "fifty dollar bills: ", "twenty dollar bills: ", "ten dollar bills: ", "five dollar bills: ", "one dollar bills: ", "quarters: ", "dimes: ", "nickels: ", "pennies: "}
Dim arrChangeAmounts(11) As Integer
Dim intCounter As Integer
strMoney = txtMoney.Text
If StringCheck(strMoney, "cur") = True Then
MsgBox("You have entered a bad numeric amount.", , "ERROR")
txtMoney.Clear()
Else
dblMoney = CDbl(strMoney)
For intCounter = 0 To 10 ' Set up 11 repetitions.
If dblMoney > arrDivisor(intCounter) Or dblMoney = arrDivisor(intCounter) Then
'division, result is a double. I.E. 1.234 gets converted to integer and drops the decimal portion
arrChangeAmounts(intCounter) = CInt(dblMoney / arrDivisor(intCounter))
'updates the label array with a bill/change type and ammount of that type
LabelArray(intCounter + 1).Text = arrChangeType(intCounter) & arrChangeAmounts(intCounter)
'the adds all the change made and puts it in a disabled textbox
dblTotal = dblTotal + (arrChangeAmounts(intCounter) * arrDivisor(intCounter))
' i made my own modulus function to get over the improper division
dblMoney = ModNum(dblMoney, arrDivisor(intCounter))
' this tries to fix the problem with MS's version of division
dblMoney = dblMoney + 0.00001
Else
LabelArray(intCounter + 1).Text = arrChangeType(intCounter) & "0"
End If
Next intCounter ' Increment intCounter.
txtTotal.Text = CStr(dblTotal)
End If
End Sub