Create and test a Visual Basic application to allow teachers to enter student results.

One dimension of the array will hold the results for up to 10 students.
The other dimension will hold up to 5 subjects.
Additionally a string based array will hold the names of the subjects.
Include a user interface to allow a teacher to enter the names of each subject, and also enter the results for each subject.
Allow for results with a value from 0 to 100 with whole numbers only.
When the "Summary" button is pressed, display the Name, Min, Max and average for each subject.

Step 1: Create a new Visual Basic project

- Open Visual Studio and create a new Visual Basic Windows Forms Application project.

Step 2: Design the user interface
- Open the Form designer by double-clicking on the Form in the Solution Explorer.
- Drag and drop the required controls onto the form. Place labels, textboxes, buttons, and a DataGridView control on the form.
- Design the form layout as per your preference. Your form may look something like this:

```
Label1: Subjects
Textbox1: Subject1
Textbox2: Subject2
...
Button1: Enter Results
Button2: Summary
DataGridView1: display detailed results
```

Step 3: Define variables and arrays
- In the code-behind file for the form (usually Form1.vb), define the following variables and arrays:

```vb
Private subjects As String() ' Array to hold subject names
Private results As Integer(,) ' 2D array to hold student results
```

Step 4: Initialize variables and load subject names
- In the Form_Load event handler, initialize the subjects array and load subject names from the textboxes:

```vb
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
subjects = New String(5) {} ' Initialize the subjects array with size 5
results = New Integer(10, 5) {} ' Initialize the results array with size 10x5

' Load subject names from textboxes
subjects(0) = TextBox1.Text
subjects(1) = TextBox2.Text
' And so on...
End Sub
```

Step 5: Enter student results
- In the Button1_Click event handler, store the entered results in the results array:

```vb
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For i As Integer = 0 To 9 ' Loop through each student
For j As Integer = 0 To 4 ' Loop through each subject
' Validate the entered result (whole number between 0 and 100)
Dim result As Integer = 0
If Integer.TryParse(DataGridView1.Rows(i).Cells(j).Value.ToString(), result) Then
If result >= 0 And result <= 100 Then
results(i, j) = result ' Store the result
Else
MessageBox.Show("Please enter a whole number between 0 and 100 for each result.")
End If
Else
MessageBox.Show("Please enter a valid number for each result.")
End If
Next
Next
End Sub
```

Step 6: Generate summary
- In the Button2_Click event handler, calculate and display the summary of results using MessageBox:

```vb
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For j As Integer = 0 To 4 ' Loop through each subject
Dim subjectName As String = subjects(j)
Dim subjectResults As Integer() = New Integer(9) {} ' Array to store individual results for the subject
Dim minResult As Integer = Integer.MaxValue
Dim maxResult As Integer = Integer.MinValue
Dim totalResult As Integer = 0

For i As Integer = 0 To 9 ' Loop through each student
subjectResults(i) = results(i, j) ' Store the result for the subject

' Calculate min and max results
If results(i, j) < minResult Then
minResult = results(i, j)
End If
If results(i, j) > maxResult Then
maxResult = results(i, j)
End If
totalResult += results(i, j) ' Calculate total result
Next

Dim averageResult As Double = totalResult / 10 ' Calculate average result

' Display the summary using MessageBox
MessageBox.Show("Subject: " & subjectName & vbCrLf &
"Min Result: " & minResult & vbCrLf &
"Max Result: " & maxResult & vbCrLf &
"Average Result: " & averageResult.ToString("0.00"))
Next
End Sub
```

Step 7: Run the application
- Save the project and run the application.
- Enter the subject names in the textboxes and the student results in the DataGridView.
- Click the "Enter Results" button to store the results.
- Click the "Summary" button to display the summary for each subject.

To create and test a Visual Basic application that allows teachers to enter student results, follow these steps:

1. Create a new Visual Basic project:
- Open Microsoft Visual Studio.
- Create a new Windows Forms Application project.
- Set the project name to "StudentResultsApp" (or any name you prefer).

2. Design the user interface:
- Open the Form Designer for the main Form.
- Add a Label control and set its text to "Enter Subject Names".
- Add five TextBox controls next to the Label control to allow the user to enter subject names.
- Add a Label control and set its text to "Enter Student Results".
- Add a DataGridView control below the Label control to display and enter student results.
- Add a Summary button below the DataGridView control.
- Add a Label control below the Summary button to display the summary.

3. Set up the arrays and variables:
- In the code-behind file, declare the necessary variables and arrays at the class level:
```vb
Private subjects() As String = New String(4) {} ' Array to hold subject names
Private results(9, 4) As Integer ' Array to hold student results
```

4. Handle the Form_Load event:
- Double-click on the Form to generate the `Form_Load` event handler.
- In the event handler, set the column headers of the DataGridView control to the subject names:
```vb
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i As Integer = 0 To subjects.Length - 1
DataGridView1.Columns.Add(subjects(i), subjects(i))
Next
End Sub
```

5. Handle the Summary button click:
- Double-click on the Summary button to generate the button's click event handler.
- In the event handler, calculate the minimum, maximum, and average for each subject and display the summary:
```vb
Private Sub SummaryButton_Click(sender As Object, e As EventArgs) Handles SummaryButton.Click
SummaryLabel.Text = "" ' Clear the summary label

For col As Integer = 0 To subjects.Length - 1
Dim subjectName As String = subjects(col)

Dim subjectResults() As Integer = New Integer(9) {}
For row As Integer = 0 To 9
subjectResults(row) = results(row, col)
Next

Dim minResult As Integer = subjectResults.Min()
Dim maxResult As Integer = subjectResults.Max()
Dim avgResult As Double = subjectResults.Average()

SummaryLabel.Text += $"Subject: {subjectName} Min: {minResult} Max: {maxResult} Avg: {avgResult:F2}{Environment.NewLine}"
Next
End Sub
```

6. Handle the CellValidating event of the DataGridView control:
- Double-click on the DataGridView control to generate the `CellValidating` event handler.
- In the event handler, validate that the entered result is a whole number between 0 and 100:
```vb
Private Sub DataGridView1_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
Dim enteredValue As String = e.FormattedValue.ToString()
Dim result As Integer = 0
If Not Integer.TryParse(enteredValue, result) OrElse result < 0 OrElse result > 100 Then
e.Cancel = True
DataGridView1.Rows(e.RowIndex).ErrorText = "Invalid result. Please enter a whole number between 0 and 100."
End If
End Sub
```

7. Implement the Subject Names TextBoxes' TextChanged events:
- Assign the entered subject names to the subjects array:
```vb
Private Sub SubjectNameTextBox_TextChanged(sender As Object, e As EventArgs) Handles SubjectNameTextBox1.TextChanged, SubjectNameTextBox2.TextChanged, SubjectNameTextBox3.TextChanged, SubjectNameTextBox4.TextChanged, SubjectNameTextBox5.TextChanged
Dim textBox As TextBox = CType(sender, TextBox)
Dim index As Integer = Integer.Parse(textBox.Name(textBox.Name.Length - 1)) - 1
subjects(index) = textBox.Text
DataGridView1.Columns(index).HeaderText = textBox.Text
End Sub
```

8. Implement the DataGridView CellValueChanged event:
- Assign the entered results to the results array:
```vb
Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
If e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0 Then
Dim enteredValue As Integer = Integer.Parse(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString())
results(e.RowIndex, e.ColumnIndex) = enteredValue
End If
End Sub
```

9. Test the application:
- Run the application.
- Enter subject names in the TextBox controls.
- Enter student results in the DataGridView control.
- Click the Summary button to display the summary.
- Verify that the summary displays the name, minimum, maximum, and average for each subject.

This completes the step-by-step process to create and test a Visual Basic application that allows teachers to enter student results.