Click here to Skip to main content
14,879,397 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Module Module1

Public Structure student
Dim name As String
Dim marks() As Integer
End Structure

Sub Main()

Dim ocra(2) As student
ReDim ocra(2).marks(2)

ocra(0).marks(0) = 52

Console.WriteLine(ocra(0).marks(0))
Console.ReadLine()

End Sub

End Module

--> When I run this code, I keep getting this error:
Object reference not set to an instance of an object.

Can someone help me with this?
Posted

1 solution

I think:
When you execute the command
VB
ReDim ocra(2).marks(2)
you only declare the size of ocra(2).marks() to be 2. With ocra(0).marks(), you did not declare!
You replace
VB
ReDim ocra(2).marks(2)

by
VB
ReDim ocra(0).marks(2)


Have a good luck! (I'm not supporter in VB.NET).
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900