0
我有一個簡單的問題。我所需要做的就是從選定的組合框項目中獲取數組信息。我知道關於combobox.selectedindex但這不是我的問題。我需要檢索數組信息,所以一旦我選擇學生名稱,它會顯示他們的原始成績和彎曲的字母等級。我已經完成了數學,除了這個之外,我已經完成了所有的工作。這是我的代碼。從選定的組合框項目獲取陣列信息。
Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
Dim Line_String As String
Dim ArraySize_Integer As Integer = 0
Dim Grades_StreamReader As IO.StreamReader
Dim i As Integer = 0
Dim GradesFile_String As String = "Grades.txt" 'To hold the filename for opening
Dim DialogResponse As DialogResult
Dim x_Integer As Integer
Dim Mean_Decimal As Double = 0
Dim Total_Integer As Double = 0
Dim sum As Double
Dim stDev As Double
Dim x As Integer
Dim y As Integer
Dim orgScore As Integer
'Prompt to open the file
'Set the initial folder to display
OpenFileDialog1.InitialDirectory = IO.Directory.GetCurrentDirectory
'Open the file
With OpenFileDialog1
'Begin in the current folder
.InitialDirectory = Directory.GetCurrentDirectory()
.FileName = "Grades.txt"
.Title = "Select File or Directory for File"
'Filter to show only .txt files
OpenFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
'Display the open file dialog box
DialogResponse = .ShowDialog()
End With
'Get the filename
GradesFile_String = OpenFileDialog1.FileName
'Connect to the file
Grades_StreamReader = IO.File.OpenText(GradesFile_String)
'Read the file into a structure array until it runs out of data
Do Until Grades_StreamReader.Peek = -1
'Raed the data
Line_String = Grades_StreamReader.ReadLine
'Split the line into the fields
StringArray_String = Line_String.Split(","c)
'Dynamically size the array of structures
ReDim Preserve StudentData_Person(ArraySize_Integer)
'Assign the fields to the structure, trimming the space
StudentData_Person(ArraySize_Integer).Name_String = StringArray_String(0).Trim
StudentData_Person(ArraySize_Integer).Grade_String = StringArray_String(1).Trim
'Increment for the next array element
ArraySize_Integer += 1
'Populate the combo box
Students_ComboBox.Items.Add(StringArray_String(0))
Loop
'Close the file
Grades_StreamReader.Close()
'Count the scores
'Convert from String to Integer
Scores_TextBox.Text = ArraySize_Integer.ToString
'Calculate the mean
If StudentData_Person.Length > 0 Then
For x_Integer = 0 To StudentData_Person.Length - 1
Total_Integer += CInt(StudentData_Person(x_Integer).Grade_String)
Next
Mean_Decimal = Total_Integer/StudentData_Person.Length
End If
Mean_TextBox.Text = Mean_Decimal.ToString
'Calculate the Standard Deviation
If StudentData_Person.Length > 0 Then
For x = 0 To StudentData_Person.Length - 1
sum += ((CInt(StudentData_Person(x).Grade_String) - Mean_Decimal)^2)
Next
stDev = Math.Round(Math.Sqrt(sum/(x - 1)), 2)
End If
stDev_TextBox.Text = stDev.ToString
'Get information from ComboBox Selected Entry
Students_ComboBox.SelectedIndex
'Determine letter grade
For y = 0 To StudentData_Person.Length
If CInt(StudentData_Person(x).Grade_String) >= Mean_Decimal + (1.5 * stDev) Then
CurvedGrade_TextBox.Text = "A"
End If
If (Mean_Decimal + (0.5 * stDev)) <= CInt(StudentData_Person(x).Grade_String) And CInt(StudentData_Person(x).Grade_String) < (Mean_Decimal + (1.5 * stDev)) Then
CurvedGrade_TextBox.Text = "B"
End If
If (Mean_Decimal - (0.5 * stDev)) <= CInt(StudentData_Person(x).Grade_String) And CInt(StudentData_Person(x).Grade_String) < (Mean_Decimal + (1.5 * stDev)) Then
CurvedGrade_TextBox.Text = "C"
End If
If (Mean_Decimal - (1.5 * stDev)) <= CInt(StudentData_Person(x).Grade_String) And CInt(StudentData_Person(x).Grade_String) < (Mean_Decimal + (1.5 * stDev)) Then
CurvedGrade_TextBox.Text = "D"
End If
If CInt(StudentData_Person(x).Grade_String) < (Mean_Decimal - (1.5 * stDev)) Then
CurvedGrade_TextBox.Text = "F"
End If
Next
End Sub
End Class
我還要再需要從這個檢索信息並計算他們的分數給出,並將它推回給該文本框,我可以做的。
請問我只是做
originalscore_textbox.text = StudentData_Person(SelectedIndex)
curvedgrade_textbox.text = 'something like what's above this line
或類似的東西,我知道這肯定是不對的,我只是你們展示我的思維理念。任何問題,請問我會盡我所能解釋他們。但這實際上就是我所需要的,我已經完成了我的程序哈哈。