Friday, October 1, 2010

October 1st 2010

Howdy!

I'm going to do a quick tutorial on fixed arrays written by Michael Halvorson.


Public Class Form1

Dim Temperatures(0 To 6) As Single

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

End Sub

Private Sub btnTemps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTemps.Click
Dim prompt, title As String
Dim i As Short
prompt = "Enter the day's high temperature."

'' the UBound function will be used for future flexibility
For i = 0 To UBound(Temperatures)
title = "Day " & (i + 1)
Temperatures(i) = InputBox(prompt, title)
Next
End Sub

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim Result As String
Dim i As Short
Dim Total As Single = 0
Result = "High temperatures for the week:" & vbCrLf & vbCrLf
For i = 0 To UBound(Temperatures)
Result = Result & "Day " & (i + 1) & vbTab & _
Temperatures(i) & vbCrLf
Total = Total + Temperatures(i)
Next
''notice how result is repeated on both sides of the equal side to preserve the information
Result = Result & vbCrLf & _
"Average temperature: " & Format(Total / 7, "0.0")
txtDisplay.Text = Result
End Sub
End Class

No comments: