Newbie Structure question

xceph

New member
Joined
Sep 23, 2008
Messages
1
Programming Experience
Beginner
Hi, Im new to VB.net and am running into a small problem.

I've created the following structure

VB.NET:
Public Structure convertedCodes
    Dim code As String
    Dim field As List(Of String)
End Structure

and I try to create an instance as follows:
VB.NET:
                Dim temp As New convertedCodes
                temp.code = oldc.code
                temp.field.Add(oldc.field)

and it crashes horribly!

I get "Object reference not set to an instance of an object.", so I am assuming there is a real problem with creating lists in a structure, and anyone who could offer assistance, or a better approach would make my day.

Cheers!
-Andrew
 
Hi, Im new to VB.net and am running into a small problem.

I've created the following structure

Public Structure convertedCodes
Dim code As String
Dim field As List(Of String)
End Structure

and I try to create an instance as follows:

Dim temp As New convertedCodes
temp.code = oldc.code
temp.field.Add(oldc.field)

and it crashes horribly!

I get "Object reference not set to an instance of an object.", so I am assuming there is a real problem with creating lists in a structure, and anyone who could offer assistance, or a better approach would make my day.

Cheers!
-Andrew
Your List(Of String) isn't set to an instance of an object, once you set it to one, problem go away

For a case like this, I would use a class instead of a structure, but that's just me
 
I agree with JuggaloBrotha, putting it into a class would be better. As an additional option, you could input it into a typed dataset with two linked tables.
 
you could input it into a typed dataset with two linked tables.
Yikes, I would create a class to handle the two tables in the dataset if it were done this way. Which means either way, creating a class would be involved.
 
Back
Top