First i would like to say hi i am new here and new to programming. im currently takeing an intor to progrmming class useing vb 2008 express edition. so basicly im a newbe. now as for my question. i had to write a program for class as a lab assignment The 12 days of christmas. i was able to write part of it but couldnt quite get it runnin rite. finaly my teacher sat down real fast and fixed my mistakes so it runs fine and i handed it in. the problem im havein is that the professor didnr explain to me wat i did wrong or why wat she did works so i have no idea whats what in the program. it basicly comes down to i dont understand Loops, For Next, or Arrays. if someone could explain to me wats goin on in the program and why it all works i think it would help me understand things finally. heres the code, runs perfectly and does exactly wat it is supposed to.
Code:
Public Class frm12DaysOfChristmas
Dim itemName(12) As String
Dim itemCost(12) As Double
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim InputDay As Integer
Dim CostOfDay As Double = 0
Dim TotalCost As Double = 0
InputDay = CInt(mtxtDayNumber.Text)
lstResults.Items.Clear()
If (CInt(InputDay) <= 0) Or (CInt(InputDay) >= 13) Then
MsgBox("Please enter a number from 1 to 12")
mtxtDayNumber.Clear()
mtxtDayNumber.Focus()
Else
For dayNum As Integer = 1 To InputDay
lstResults.Items.Add(itemName(dayNum))
CostOfDay = dayNum * itemCost(dayNum) + CostOfDay
Next
lstResults.Items.Add(FormatCurrency(CostOfDay))
CostOfDay = 0
'Grand Total
For iCount As Integer = 1 To 12
For dayNum As Integer = 1 To iCount
CostOfDay = dayNum * itemCost(dayNum) + CostOfDay
Next
Next
lstResults.Items.Add("Total Cost " & (FormatCurrency(CostOfDay)))
End If
End Sub
Private Sub frm12DaysOfChristmas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
itemName(1) = "1 Partridge in a pear tree"
itemName(2) = "2 Turtle doves"
itemName(3) = "3 French hens"
itemName(4) = "4 Calling birds"
itemName(5) = "5 Golden rings"
itemName(6) = "6 Geese a laying"
itemName(7) = "7 Swans a swimming"
itemName(8) = "8 Maids a milking"
itemName(9) = "9 Ladies dancing"
itemName(10) = "10 Lords a leaping"
itemName(11) = "11 Pipers piping"
itemName(12) = "12 Drummers drumming"
itemCost(1) = 164.99
itemCost(2) = (20.0)
itemCost(3) = (15.0)
itemCost(4) = (149.99)
itemCost(5) = (79.0)
itemCost(6) = (60.0)
itemCost(7) = (600.0)
itemCost(8) = (5.85)
itemCost(9) = (528.8)
itemCost(10) = (428.51)
itemCost(11) = (201.22)
itemCost(12) = (199.82)
End Sub
End Class
Comment