Trouble Instanciating Structures

G

Guest

I'm having trouble assigning values to a structure that has been created in a
Module. When I run the Main Subroutine it errors out when I try to assign a
value to the Id1 array with "Object not set to instance..." blah blah - even
though I have clearly just instanciated it in the previous line.

Any ideas?

Thanks,
John (see code below)

Module Main

Structure zFuheader
Dim Id1() As Byte
Dim Id2() As Byte
Dim Id3() As Byte
Dim Id4() As Byte
End Structure

Sub Main()
Dim zHeader As zFuheader
Try
zHeader = New zFuheader
zHeader.Id1(1) = Byte.Parse("1")
Catch ex As Exception
Console.Writeline(ex.Message)
End Try
End Sub

End Module
 
G

Guest

It's not the structure that needs instantiated, it's the array. This should
work:

Dim zHeader As zFuheader
zHeader.Id1 = New Byte() {1}

Tony
 
G

Guest

Excellent! That does the trick. Thanks Tony.


tlkerns said:
It's not the structure that needs instantiated, it's the array. This should
work:

Dim zHeader As zFuheader
zHeader.Id1 = New Byte() {1}

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top