AddEntry(StudentIndex): Display entry in ListBox - optional at this point.
StudentIndex += 1: Get ready for next entry.
Help Support this site - Click this ad
The following event occurs when a user clicks on the ListBox.
Private Sub lstDisplay_SelectedIndexChanged: Generated Event by Visual Basic ListBox Click.
Dim Index As Integer: A variable to contain the location of the mouse-click.
Index = lstDisplay.SelectedIndex: Determine the entry corresponding to the Visual Basic ListBox Click.
DisplaySelectedStudent(Index): Display the student information that correspond to the user selection.
The following Sub transfers data from a structure element to the TextBoxes on the form:
Private Sub DisplaySelectedStudent(ByRef Index As Integer)
txtFirstName.Text = Student(Index).FirstName
txtLastName.Text = Student(Index).LastName
txtStudentID.Text = Student(Index).ID
txtStudentGPA.Text = Student(Index).GPA.ToString(".00")
End Sub
Help Support this site - Click this ad
The following Sub is Generated when the Exit Button is pressed:
Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
The following Sub is Generated when the Calculate GPA button is pressed:
Private Sub btnAverageGPA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAverageGPA.Click:
Visual Basic Event-Driven Generated Sub when Calculate GPA Button is pressed.
Dim Index As Integer: Variable used to step through each Structure element in Student Array.
Dim Sum As Double: Variable Used to hold the Sum of every GPA in Student Array.
Dim Ave As Double: Variable used to hold the calculated GPA average.
For Index = 0 To StudentIndex - 1: Step through every Array Element.
Sum += Student(Index).GPA: Sum the GPAs and retain the result in Sum.
If StudentIndex > 0 Then: Avoid /0 error.
Ave = Sum / StudentIndex: Calculate Average.
txtAverageGPA.Text = "Class Ave = " + Ave.ToString(".00"): Display Calculated Average in TextBox txtAverageGPA.
Help Support this site - Click this ad
The following Sub is Generated when the Enter Button is pressed.
Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click:
Visual Basic Event-Driven Generated Sub when Enter button is pressed.
ValidateData(): Validate Data - Update database if entered information is correct.
txtAverageGPA.Clear(): Calculated GPA is no longer valid - Clear the display.
ClearTextFields(): Clear all other fields to prepare for next entry.
The following button is pressed when the Search button is pressed:
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Visual Basic Event-Driven Generated Sub when Search button is pressed.
Dim ID As String: Container for ID value user enters as search parameter.
Dim Index As Integer: Variable to step through each Array element.
Dim MatchFound As Boolean = False: Flag used to indicate whether or not a match was found.
ID = InputBox("Please Enter the Student's SSN (ID)", "Student Search": Use Input Box to Get User Search Parameter.
ID = InputBox: Place data from Visual Basic InputBox into variable ID.
"Please Enter the Student's SSN (ID)", "Student Search": Prompt given to user.
"Student Search": Title of Visual Basic InputBox.
If ID <> "" Then: Look for a match if they didn't cancel.
For Index = 0 To StudentIndex - 1: Step through every Array element.
If ID = Student(Index).ID Then: Test for Match.
DisplaySelectedStudent(Index): Place the matched data in the Visual Basic form TextBoxes.
MatchFound = True: Set Flag as successful match found.
Display notification if no matches were found:
If MatchFound = False Then
MessageBox.Show("No Match Found for " + ID)
ClearTextFields()
End If
Help Support this site - Click this ad
The following event is generated by pressing the Display Button:
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click:
Visual Basic Event-Driven Generated Sub when Display button is pressed.
lstDisplay.Items.Clear(): Visual Basic statement to clear ListBox control.
Dim Index As Integer: Variable used to step through every Array element.
For Index = 0 To StudentIndex - 1: Step through every Array Structure Element.
AddEntry(Index): Place the corresponding entry in the Visual Basic ListBox lstDisplay.
In order to continue with this guide, and look at some amusing examples of multiform
projects,
Press the Button below: