Trouble Instanciating Structures

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
Back
Top