User input is setup through text boxes. I want to calculate the average for each student. I have made a function to do this.
What I am having trouble with is how to pass the array of test scores to the function.
Here is what I have so far:
CODE********
Public Const intMAX_STUDENTS As Integer = 6
Public Const intMAX_NUMTESTS As Integer = 5
Public student(intMAX_STUDENTS - 1) As StudentData
Public Structure StudentData
Dim strStudentName As String
Dim dblTestscores() As Double
Dim dblAverage As Double
End Structure
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For intIndex = 0 To (student.Length - 1)
ReDim student(intIndex).dblTestscores(intMAX_NUMTESTS - 1)
Next
End Sub
Private Sub btnCalcAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcAverage.Click
student(0).dblAverage = CalcAverage(student(0).dblTestscores)[/color]
lblStudent1Average.Text = student(0).dblAverage.ToString("n1")
End Sub
Function CalcAverage(ByVal student As StudentData) As Double
Dim dblTotal As Single = 0
Dim dblAverageScore As Double
Dim intCount As Integer
With student
For intCount = 0 To (student.dblTestscores.Length - 1)
dblTotal += student.dblTestscores(intCount)
Next
dblAverageScore = dblTotal / student.dblTestscores.Length
Return dblAverageScore
End With
End Function
Any input would be great
Thanks
This post has been edited by AdamSpeight2008: 02 February 2012 - 02:54 PM

New Topic/Question
Reply



MultiQuote




|