为什么我在声明VB.NET后得到一个空引用?

时间:2014-11-20 01:19:24

标签: arrays vb.net indexing variable-assignment declaration

为什么在我的代码中为数组'arrCourse'赋值时,我得到一个Null引用。 我在主窗体中的所有方法之外声明了数组。我想将0分配给第一个索引的唯一原因是因为当我尝试Double.Parse时,我也得到了一个N​​ull引用。

Imports System.IO

公共类frmScore

Public studentReport As StreamWriter

'studentReport = File.CreateText("reportCards.txt")
'Put this declaration into a method
Public Structure StudentRecords
    Public strName As String
    Public arrCourseGrade() As Double
    Public dblAverage As Double
End Structure

Public student1 As StudentRecords




'Calculating Averages
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
    student1.arrCourseGrade(0) = 1
    student1.arrCourseGrade(1) = 2


    If Double.TryParse(txtS1Course1.Text, student1.arrCourseGrade(0)) Then

    Else
        MessageBox.Show("Student 1, Course 1 grade, must be numeric")
    End If


End Sub

结束班

0 个答案:

没有答案