yea it does i didnt get that far. i need it to pass the values from "data.txt" which is in the debug folder. to three functions
One function to calculate the range of data.txt, one function to calculate the mean of data.txt, and another function to calculate the standard deviation. its pretty hard!
-- Thu Dec 15, 2011 10:04 pm --
got all the way to the range function
- Code: Select all
Option Strict On
Option Explicit On
Partial Public Class Form1
Private scores() As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
' First, load the scores from the file into memory
Call LoadScores()
Dim value As Double
Dim value2 As Double
Dim value3 As Double
'calculate the mean
value = CalculateMean()
OutputListBox.Items.Add("Mean = " & value.ToString)
'calculate the range
value2 = CalculateRange()
OutputListBox.Items.Add("Range = " & value2.ToString)
'calculate the standard deviation
value2 = Calculatedeviation()
OutputListBox.Items.Add("Standard deviation = " & value3.ToString)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub LoadScores()
Dim stringScores() As String
' Reads all of the scores in the file into an array of strings
stringScores = IO.File.ReadAllLines("data.txt")
' Resize the scores array to hold all of the values in the file
ReDim scores(stringScores.Length)
Dim counter As Integer
' converts strings to numbers, and store them in scores
For Each sValue As String In stringScores
' Converts the string value from the file into a double and stores it in the current location in the scores array
scores(counter) = CDbl(sValue)
counter += 1
Next
End Sub
' Calculates mean
Function CalculateMean() As Double
If scores.Length <> 0 Then
Dim total As Double
For Each value As Double In scores
total += value
Next
Return total / scores.Length
Else
' Avoid a divide by zero error
Return 0
End If
End Function
Function CalculateRange() As Double
If scores.Length <> 0 Then
Dim total As Double
For Each value As Double In scores
total += value
Next
Return total
End If
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
End Class