kittyciara
12-01-2008, 09:20 PM
So I'm trying to write a program in Visual Basic. The program is supposed to read an Access database of student information and write it to a form and allow the user to maintain the information, search and select the information by student last name and display a class average. I've got the access database and most of the programming done. The only thing causing me issues is the class average button.
The click event procedure for the class average button is supposed to read from 3 parallel arrays and display the results in the name list box concatenated like this: Last Name, First Name, Student Average ( this would be a number). So far I have figured out how to make the list box display the last name, and first name but the student average and the class average are giving me problems. Here is my code and I attached a SS of my form.
Any help is appreciated! looooooove you!
Public Class mainForm
Private Sub Table1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Table1BindingNavigatorSaveItem.Click
Me.Validate()
Me.Table1BindingSource.EndEdit()
Me.Table1TableAdapter.Update(Me.Student_Informatio nDataSet.Table1)
End Sub
Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
'TODO: This line of code loads data into the 'Student_InformationDataSet.Table1' table.
'You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Student_InformationD ataSet.Table1)
SplashScreenForm.ShowDialog()
End Sub
Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles exitButton.Click
Me.Close()
End Sub
Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles calcButton.Click
Dim Project_1 As Decimal
Dim Project_2 As Decimal
Dim Mid__Term_Grade As Decimal
Dim FInal__Exam_Grade As Decimal
Dim HW_1 As Decimal
Dim HW_2 As Decimal
Dim HW_3 As Decimal
Dim HW_4 As Decimal
Dim HW_5 As Decimal
Dim HW_7 As Decimal
Dim HW_8 As Decimal
Dim HW_9 As Decimal
Dim HW_10 As Decimal
Dim HW_Average As Decimal
Dim studentAverage As Decimal
Dim isConverted As Boolean
isConverted = Decimal.TryParse(studentAverageLabel.Text, studentAverage)
Project_1 = Project_1TextBox.Text * 0.2
Project_2 = Project_2TextBox.Text * 0.2
Mid__Term_Grade = Mid__Term_GradeTextBox.Text * 0.2
FInal__Exam_Grade = FInal__Exam_GradeTextBox.Text * 0.2
HW_1 = HW_1TextBox.Text
HW_2 = HW_2TextBox.Text
HW_3 = HW_3TextBox.Text
HW_4 = HW_4TextBox.Text
HW_5 = HW_5TextBox.Text
HW_7 = HW_7TextBox.Text
HW_8 = HW_8TextBox.Text
HW_9 = HW_9TextBox.Text
HW_10 = HW_10TextBox.Text
HW_Average = (((HW_1 + HW_2 + HW_3 + HW_4 + HW_5 + HW_7 + HW_8 + HW_9 + HW_10) / 9) * 0.2)
studentAverage = Project_1 + Project_2 + Mid__Term_Grade + FInal__Exam_Grade + HW_Average
studentAverageLabel.Text = studentAverage.ToString("N2")
End Sub
Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorMoveNextItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub BindingNavigatorMovePreviousItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorMovePreviousItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub BindingNavigatorMoveLastItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorMoveLastItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub BindingNavigatorMoveFirstItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorMoveFirstItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorAddNewItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub searchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles searchButton.Click
Try
Me.Table1TableAdapter.FillBySearch(Me.Student_Info rmationDataSet.Table1, searchTextBox.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub OrderByLastNameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrderByLastNameToolStripMenuItem.Click
Try
Me.Table1TableAdapter.FillByLastName(Me.Student_In formationDataSet.Table1)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub SearchSeniorsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchSeniorsToolStripMenuItem.Click
Try
Me.Table1TableAdapter.FillBySenior(Me.Student_Info rmationDataSet.Table1)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub ResetToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetToolStripMenuItem.Click
Try
Me.Table1TableAdapter.Fill(Me.Student_InformationD ataSet.Table1)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub ToolTip1_Popup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup
End Sub
Private Sub FillBySearchToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBySearchToolStripButton.Click
Try
Me.Table1TableAdapter.FillBySearch(Me.Student_Info rmationDataSet.Table1, Last_NameToolStripTextBox.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub Last_NameToolStripTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Last_NameToolStripTextBox.Click
End Sub
Private Sub resetButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetButton.Click
Try
Me.Table1TableAdapter.Fill(Me.Student_InformationD ataSet.Table1)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
nameListBox.Items.Clear()
End Sub
Private Sub Last_NameToolStripLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Last_NameToolStripLabel.Click
studentAverageLabel.Text = ""
End Sub
Private Sub showButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles showButton.Click
Dim UpperBound As Integer
Dim count As Integer
' declare parallel arrays
Dim lastName(0) As String
Dim firstName(0) As String
Dim studentAverage(0) As String
For Each record As DataRow In Student_InformationDataSet.Table1
'write student ID and class average to parallel arrays
lastName(UpperBound) = (record.Item("Last Name"))
firstName(UpperBound) = (record.Item("First Name"))
count = count + 1
'redeclare arrays, increase size of array by 1 and preserve entries
ReDim Preserve lastName(UpperBound + 1)
ReDim Preserve firstName(UpperBound + 1)
nameListBox.Items.Add(lastName(UpperBound) & ", " & firstName(UpperBound))
Next record
nameListBox.SelectedIndex = 0
End Sub
End Class
The click event procedure for the class average button is supposed to read from 3 parallel arrays and display the results in the name list box concatenated like this: Last Name, First Name, Student Average ( this would be a number). So far I have figured out how to make the list box display the last name, and first name but the student average and the class average are giving me problems. Here is my code and I attached a SS of my form.
Any help is appreciated! looooooove you!
Public Class mainForm
Private Sub Table1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Table1BindingNavigatorSaveItem.Click
Me.Validate()
Me.Table1BindingSource.EndEdit()
Me.Table1TableAdapter.Update(Me.Student_Informatio nDataSet.Table1)
End Sub
Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
'TODO: This line of code loads data into the 'Student_InformationDataSet.Table1' table.
'You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Student_InformationD ataSet.Table1)
SplashScreenForm.ShowDialog()
End Sub
Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles exitButton.Click
Me.Close()
End Sub
Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles calcButton.Click
Dim Project_1 As Decimal
Dim Project_2 As Decimal
Dim Mid__Term_Grade As Decimal
Dim FInal__Exam_Grade As Decimal
Dim HW_1 As Decimal
Dim HW_2 As Decimal
Dim HW_3 As Decimal
Dim HW_4 As Decimal
Dim HW_5 As Decimal
Dim HW_7 As Decimal
Dim HW_8 As Decimal
Dim HW_9 As Decimal
Dim HW_10 As Decimal
Dim HW_Average As Decimal
Dim studentAverage As Decimal
Dim isConverted As Boolean
isConverted = Decimal.TryParse(studentAverageLabel.Text, studentAverage)
Project_1 = Project_1TextBox.Text * 0.2
Project_2 = Project_2TextBox.Text * 0.2
Mid__Term_Grade = Mid__Term_GradeTextBox.Text * 0.2
FInal__Exam_Grade = FInal__Exam_GradeTextBox.Text * 0.2
HW_1 = HW_1TextBox.Text
HW_2 = HW_2TextBox.Text
HW_3 = HW_3TextBox.Text
HW_4 = HW_4TextBox.Text
HW_5 = HW_5TextBox.Text
HW_7 = HW_7TextBox.Text
HW_8 = HW_8TextBox.Text
HW_9 = HW_9TextBox.Text
HW_10 = HW_10TextBox.Text
HW_Average = (((HW_1 + HW_2 + HW_3 + HW_4 + HW_5 + HW_7 + HW_8 + HW_9 + HW_10) / 9) * 0.2)
studentAverage = Project_1 + Project_2 + Mid__Term_Grade + FInal__Exam_Grade + HW_Average
studentAverageLabel.Text = studentAverage.ToString("N2")
End Sub
Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorMoveNextItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub BindingNavigatorMovePreviousItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorMovePreviousItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub BindingNavigatorMoveLastItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorMoveLastItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub BindingNavigatorMoveFirstItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorMoveFirstItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles BindingNavigatorAddNewItem.Click
studentAverageLabel.Text = ""
End Sub
Private Sub searchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles searchButton.Click
Try
Me.Table1TableAdapter.FillBySearch(Me.Student_Info rmationDataSet.Table1, searchTextBox.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub OrderByLastNameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrderByLastNameToolStripMenuItem.Click
Try
Me.Table1TableAdapter.FillByLastName(Me.Student_In formationDataSet.Table1)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub SearchSeniorsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchSeniorsToolStripMenuItem.Click
Try
Me.Table1TableAdapter.FillBySenior(Me.Student_Info rmationDataSet.Table1)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub ResetToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetToolStripMenuItem.Click
Try
Me.Table1TableAdapter.Fill(Me.Student_InformationD ataSet.Table1)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub ToolTip1_Popup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup
End Sub
Private Sub FillBySearchToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBySearchToolStripButton.Click
Try
Me.Table1TableAdapter.FillBySearch(Me.Student_Info rmationDataSet.Table1, Last_NameToolStripTextBox.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
End Sub
Private Sub Last_NameToolStripTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Last_NameToolStripTextBox.Click
End Sub
Private Sub resetButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetButton.Click
Try
Me.Table1TableAdapter.Fill(Me.Student_InformationD ataSet.Table1)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
studentAverageLabel.Text = ""
nameListBox.Items.Clear()
End Sub
Private Sub Last_NameToolStripLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Last_NameToolStripLabel.Click
studentAverageLabel.Text = ""
End Sub
Private Sub showButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles showButton.Click
Dim UpperBound As Integer
Dim count As Integer
' declare parallel arrays
Dim lastName(0) As String
Dim firstName(0) As String
Dim studentAverage(0) As String
For Each record As DataRow In Student_InformationDataSet.Table1
'write student ID and class average to parallel arrays
lastName(UpperBound) = (record.Item("Last Name"))
firstName(UpperBound) = (record.Item("First Name"))
count = count + 1
'redeclare arrays, increase size of array by 1 and preserve entries
ReDim Preserve lastName(UpperBound + 1)
ReDim Preserve firstName(UpperBound + 1)
nameListBox.Items.Add(lastName(UpperBound) & ", " & firstName(UpperBound))
Next record
nameListBox.SelectedIndex = 0
End Sub
End Class