7
Do Loop with Interest Please see speaker notes for additional information!

Do Loop with Interest Please see speaker notes for additional information!

Embed Size (px)

Citation preview

Page 1: Do Loop with Interest Please see speaker notes for additional information!

Do Loop with Interest

Please see speaker notes for additional information!

Page 2: Do Loop with Interest Please see speaker notes for additional information!

InterestInterest

Page 3: Do Loop with Interest Please see speaker notes for additional information!

InterestInterest

Private Sub cmdCalculate_Click() Dim wrkInt As Single, wrkYr As Integer, wrkDeposit As Single, wrkToDate As Single wrkInt = Val(txtInt.Text) wrkYr = 0 wrkDeposit = Val(txtDeposit.Text) wrkToDate = wrkDeposit txtDeposit.Text = Format(txtDeposit.Text, "Currency") Do wrkToDate = wrkToDate * wrkInt + wrkToDate wrkYr = wrkYr + 1 If wrkYr Mod 7 = 0 Then wrkPrintToDate = Format(wrkToDate, "$##,##0.00") picYrAmt.Print Format(wrkYr, "@@@@"); Tab(6); Format(wrkPrintToDate, "@@@@@@@@@@@") End If Loop Until wrkToDate > 10000 txtAnswer.Text = "In " & wrkYr & " years, you earned " & Format(wrkToDate, "Currency") End Sub

Private Sub cmdClear_Click()picYrAmt.ClstxtDepositor.Text = ""txtDeposit.Text = ""txtInt.Text = ""txtAnswer.Text = ""End Sub

Private Sub cmdExit_Click() EndEnd Sub

Note that the DO LOOP continues until wrkToDate > 10000. Then the amount you have earned is shown in the text box.

Every 7 years the amount in wrkToDate is displayed in the box. This is done using Mod 7. When the answer is evenly divisible by 7 then the information is printed.

Page 4: Do Loop with Interest Please see speaker notes for additional information!

If wrkYr Mod 7 = 0 Then wrkPrintToDate = Format(wrkToDate, ” $##,##0.00") picYrAmt.Print Format(wrkYr, "@@@@"); Tab(6); Format(wrkPrintToDate, "@@@@@@@@@@@") End If

InterestInterest

This example uses formatting with the format function: Format(expression,str) where expression is the thing to be formatted using the rules that appear in str). There are predefined format such as “Currency” which display in leading dollar format, ”, “Percent” which displays with a percent sign and the data multiplied by 100, and “General Number” which displays as is etc. You can also use symbols such as the # which simple shows a space for a digit, 0 which means that the 0 should print, $ which will show etc. The @ means to define a string field with this many characters and fill with spaces if there are not enough.

txtDeposit.Text = Format(txtDeposit.Text, "Currency")

Page 5: Do Loop with Interest Please see speaker notes for additional information!

InterestInterest

The textbox where the amount of money is displayed takes multiple lines. Note that MultiLine must be set to True.

Page 6: Do Loop with Interest Please see speaker notes for additional information!

Private Sub cmdCalculate_Click() Dim wrkInt As Single, wrkYr As Integer, wrkDeposit As Single, wrkToDate As Single wrkInt = Val(txtInt.Text) wrkYr = 0 wrkDeposit = Val(txtDeposit.Text) wrkToDate = wrkDeposit txtDeposit.Text = Format(txtDeposit.Text, "Currency") Do While wrkToDate < 10000 wrkToDate = wrkToDate * wrkInt + wrkToDate wrkYr = wrkYr + 1 If wrkYr Mod 7 = 0 Then wrkPrintToDate = Format(wrkToDate, "$##,##0.00") picYrAmt.Print Format(wrkYr, "@@@@"); Tab(6); Format(wrkPrintToDate, "@@@@@@@@@@@") End If Loop txtAnswer.Text = "In " & wrkYr & " years, you earned " & Format(wrkToDate, "Currency")End Sub

Private Sub cmdClear_Click()picYrAmt.ClstxtDepositor.Text = ""txtDeposit.Text = ""txtInt.Text = ""txtAnswer.Text = ""End Sub

Private Sub cmdExit_Click() EndEnd Sub

Interest2Interest2

Page 7: Do Loop with Interest Please see speaker notes for additional information!

Private Sub cmdCalculate_Click() Dim wrkInt As Single, wrkYr As Integer, wrkDeposit As Single, wrkToDate As Single wrkInt = Val(txtInt.Text) wrkYr = 0 wrkDeposit = Val(txtDeposit.Text) wrkToDate = wrkDeposit txtDeposit.Text = Format(txtDeposit.Text, "Currency") Do While wrkToDate < 10000 wrkToDate = wrkToDate * wrkInt + wrkToDate wrkYr = wrkYr + 1 If wrkYr Mod 7 = 0 Then wrkPrintToDate = Format(wrkToDate, "$##,##0.00") picYrAmt.Print Format(wrkYr, "@@@@"); Tab(6); Format(wrkPrintToDate, "@@@@@@@@@@@") End If Loop txtAnswer.Text = "In " & wrkYr & " years, you earned " & Format(wrkToDate, "Currency")End Sub

Private Sub cmdCalculate_Click() Dim wrkInt As Single, wrkYr As Integer, wrkDeposit As Single, wrkToDate As Single wrkInt = Val(txtInt.Text) wrkYr = 0 wrkDeposit = Val(txtDeposit.Text) wrkToDate = wrkDeposit txtDeposit.Text = Format(txtDeposit.Text, "Currency") Do wrkToDate = wrkToDate * wrkInt + wrkToDate wrkYr = wrkYr + 1 If wrkYr Mod 7 = 0 Then wrkPrintToDate = Format(wrkToDate, "$##,##0.00") picYrAmt.Print Format(wrkYr, "@@@@"); Tab(6); Format(wrkPrintToDate, "@@@@@@@@@@@") End If Loop Until wrkToDate > 10000 txtAnswer.Text = "In " & wrkYr & " years, you earned " & Format(wrkToDate, "Currency") End Sub