473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Trouble Instanciating Structures

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
Aug 22 '06 #1
2 939
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
Aug 22 '06 #2
Excellent! That does the trick. Thanks Tony.
"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
Aug 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DPhelps | last post by:
I have a multithreaded Python shell server (base on the sample code 'pysvr.py') that uses a C-based extension class. The trouble I'm having is that I cannot figure out a way to create a Python...
1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
12
by: Ney André de Mello Zunino | last post by:
Hello. I have been having some trouble dealing with bit fields. The following is a simple program that demonstrates it. #include <iomanip> #include <iostream> struct instrucao_i {
6
by: Ken Allen | last post by:
OK, I admit that I have been programming since before C++ was invented, and I have developed more than my share of assembly language systems, and even contributed to operating system and compiler...
14
by: pmclinn | last post by:
I've noticed that many programmers use classes to store data about such things like: Class Customers .....Phone ....ID ....Address End Class....
1
by: Mercy | last post by:
Hey All, This is probably a easy question, but I'm really stuck. I have a command console program written in C++, that I want to convert it to C# to make it into a windows app. The problem is...
9
suzee_q00
by: suzee_q00 | last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it....
2
by: thomasfarrow | last post by:
At work, our development team has a development standards document that insists Structures should never be used. I'm looking to change this standard but need a suitable argument in order to make...
6
by: Just Me | last post by:
Any ideas on this. I am trying to loop through an xml document to remove attributes, but Im having so much trouble, any help is appreciated //THIS IS THE EXCEPTION ( SEE CODE LINE WHERE FAILURE...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.