System.NullReferenceException

Arthy67

New member
Joined
Dec 30, 2019
Messages
3
Programming Experience
1-3
hello everyone,
I've just signed up and I am a new user of Visual Basic 2019.

I am a VB6 & VBScript developer for many years, but now I have to evolve ... and obviously the trouble is starting! :)
Here is the first problem I don't understand how to solve.

Like explainded in the Subject, the error occurs by invoking:

VB.NET:
Archive = MDIPanel.Gestore.GetArchive

where "gestore" is a my Class and the Function in particular is:

VB.NET:
Public Function Get Archive () As Object

Dim Archive (0 To NumeroTotaleEstrazioni, 0 To 10, 0 To 5) As Object
For i = 0 To NumeroTotaleEtrazioni
For j = 0 To 10
For k = 0 To 5
Archive (i, j, k) = Extraction Archive (i). Numbers (j, k)
Next k
Next j
Next i
GetArchivio = Archive

End Function

The "ArchivioEstrazioni" procedure is defined as follows:

VB.NET:
Public ArchivioEstrazioni () As TArchivioEstrazioni

where:

VB.NET:
Public Structure TExtraction Archive
Dim Numbers (,) As Integer '0 To 10, 0 To 5
Dim DataEstrazione As TDataEstrazione
End Structure

VB.NET:
Public Structure TData Extraction
Dim Day As Byte
Dim Month As Byte
Dim Anno As Integer
Dim DayWeek As String
End Structure

I have declared the Archive variable in a Module as Obect.

I hope I haven't forgotten anything ....
I await your precious comments ...

Thank you, Arturo.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,402
Location
Sydney, Australia
Programming Experience
10+
A NullReferenceException is generally quite easy to diagnose. It means that something on the lefthand side of a dot is Nothing. You use the debugger to work out what that is. In your case, there are only two possibilities. Either MDIPanel is Nothing or MDIPanel.Gestore is Nothing. I'm guessing it's the latter but you can find out easily enough. Once you know what reference is Nothing, you can work backwards to where you expected it to be set, work out why it isn't and then fix that issue.
 

Arthy67

New member
Joined
Dec 30, 2019
Messages
3
Programming Experience
1-3
Thanks jmcilhinney...
I've been forgotten to load data before calling the function.
In effect, "Gestore" was Nothing...
Thank you! :)
 
Top Bottom