Untitled
unknown
plain_text
a year ago
2.4 kB
2
Indexable
Never
' Question 3: Weekly Temperature Average Public Class Form1 Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim weeks As Integer() = {txtWeek1.Text, txtWeek2.Text, txtWeek3.Text, txtWeek4.Text, txtWeek5.Text} Dim total As Integer = 0 Dim average As Double For Each week In weeks If Not IsNumeric(week) Then MessageBox.Show("Please enter a numeric value.") Exit Sub End If total += week Next average = total / weeks.Length lblAverage.Text = "Average: " & average.ToString() End Sub Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click txtWeek1.Text = "" txtWeek2.Text = "" txtWeek3.Text = "" txtWeek4.Text = "" txtWeek5.Text = "" lblAverage.Text = "Average: " End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub End Class ' Question 4: Weekly Temperatures with Validation Public Class Form2 Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim weeks As TextBox() = {txtWeek1, txtWeek2, txtWeek3, txtWeek4, txtWeek5} Dim total As Integer = 0 Dim average As Double For Each week In weeks If Not IsNumeric(week.Text) Then StatusStrip1.Text = "Error: Please enter a numeric value for " & week.Name week.Focus() Exit Sub ElseIf week.Text < -50 Or week.Text > 130 Then StatusStrip1.Text = "Error: Temperature must be between -50 and 130 for " & week.Name week.Focus() Exit Sub End If total += week.Text Next average = total / weeks.Length lblAverage.Text = "Average: " & average.ToString() End Sub Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click txtWeek1.Text = "" txtWeek2.Text = "" txtWeek3.Text = "" txtWeek4.Text = "" txtWeek5.Text = "" lblAverage.Text = "Average: " StatusStrip1.Text = "" End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub End Class