Home All Groups Group Topic Archive Search About

Trouble Instanciating Structures

Author
22 Aug 2006 6:22 PM
redeagle
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

Author
22 Aug 2006 7:05 PM
tlkerns
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

Show quoteHide quote
"redeagle" wrote:

> 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
Author
22 Aug 2006 7:22 PM
redeagle
Excellent! That does the trick. Thanks Tony.


Show quoteHide quote
"tlkerns" wrote:

> 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
>
> "redeagle" wrote:
>
> > 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