All pastes #468465 Raw Edit

Untitled

public text v1 · immutable
·published 2007-05-03 03:50 UTC
rendered paste body
Public Class Form1

    'Creates the arrays needed fpr the program:
    'Sets the strGift array values, which are the gifts for the day
    Dim strGift() As String = {"", "Partridge in a Pear Tree", "Turtle Doves", "French Hens", "Calling Birds", "Gold Rings", "Geese-a-Laying", "Swans-A-Swimming", "Maids-a-Milking", "Ladies Dancing", "Lords-a-Leaping", "Pipers Piping", "Drummers Drumming"}
    Dim dblCostForDay(12) As Double
    Dim dblCost(12) As Double

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Sets the Cost for Day 0 to be 0, because the real values needed for the array start at 1.
        dblCostForDay(0) = 0
        'Sets the cost of the gifts (singular quantities) for each day
        dblCost(1) = 104.99
        dblCost(2) = 20.0
        dblCost(3) = 15.0
        dblCost(4) = 99.99
        dblCost(5) = 65.0
        dblCost(6) = 50.0
        dblCost(7) = 600.0
        dblCost(8) = 5.15
        dblCost(9) = 508.46
        dblCost(10) = 403.91
        dblCost(11) = 186.65
        dblCost(12) = 185.36
    End Sub

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        Dim i As Integer = 0
        Dim j As Integer = 0
        Dim k As Integer = 0
        Dim dblTotalCost As Double = 0

        'sets i to the input from the user for what day they want to display and howmuch it costs
        i = CInt(txtInput.Text)

        'Calculates the Cost for each day, which is each days cost (item price * n number of items where n is the day) + the previous days cost.
        For j = 1 To 12
            dblCostForDay(j) = (dblCost(j) * j) + dblCostForDay(j - 1)
        Next

        'Calculates the cost of all 12 days
        For k = 1 To 12
            dblTotalCost += dblCostForDay(k)
        Next

        'Outputs each gift for the day entered by the user going from the day down to day 1
        lstOutput.Items.Add("The Gift[s] for Day " & i & " are: ")
        For i = CInt(txtInput.Text) To 1 Step -1
            lstOutput.Items.Add(i & " " & strGift(i))
        Next

        'Outputs the total cost of the day chosen, and the cost of all 12 days
        lstOutput.Items.Add("")
        lstOutput.Items.Add("The Cost for day " & txtInput.Text & " is " & FormatCurrency(dblCostForDay(CInt(txtInput.Text)), 2))
        lstOutput.Items.Add("The Total Cost for all Twelve Days is " & FormatCurrency(dblTotalCost, 2))
    End Sub
End Class