0

Why am I getting a Null Reference when I assign a value to the array 'arrCourse' in my code. I declared the array outside of all methods in the main Form. The only reason I want to assign 0 to the first Index is because when I tried Double.Parse I also got a Null reference.

Imports System.IO

Public Class 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

End Class

Jon Q
  • 63
  • 1
  • 1
  • 7
  • Well I have to use structured variables. I was trying to validate the input before assigning it to the array. But either way I get a Null Reference. Isn't that the correct way you assign a value to an array though? – Jon Q Nov 20 '14 at 01:30
  • read the link - initializing arrays is amply covered (scroll down to the VB oriented answer) – Ňɏssa Pøngjǣrdenlarp Nov 20 '14 at 01:31

0 Answers0