473,804 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Writeli ne(ex.Message)
End Try
End Sub

End Module
Aug 22 '06 #1
2 961
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.Writeli ne(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.Writeli ne(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
1319
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 object from the C code. I'll detail the methods I've looked at and the troubles I'm having: Method 1) Ideally, I could get PyRun_String to work, however I cannot figure out
1
2739
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 structures. Trying to comprehend this is harder than I thought it was going to be. I should of just skipped this chapter and went right into pointers since they seem to be easier to use. But anyways here i smy question: you define a structure...
12
2222
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
4489
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 systems over the years. I have developed code in more than 30 distinct programming languages for a wide cariety of industries. But this issue of structures in C# is beginning to annoy me. I should also make it clear that I am not a big supporter...
14
15090
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
3185
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 that my program uses a third part dll. So I tried to write a wrapper class for it. Even though I think my interface looks right... the values being returned from the third party imported functions are off. Original Code:
9
7337
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. Here's the code: while ( ( fgets ( buf, BUFLEN, fin ) ) != NULL ) /* pulls a line from "fin" up to the length of BUFLEN and stores it in "buf" */ { rmNl ( buf ); /* remove new line */ if ( !lineWithBlanks ( buf ) ) { for (i = 0; buf !=...
2
2410
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 the change. I know that Structures are value types, sit on the stack, and are generally more efficient to manipulate than reference types (i.e. Classes). Structures cannot use inheritance, the finalize method or default constructors. Can anyone...
6
1727
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 OCCURS '//Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 13, position 11. //THE XHTML TEXT WHICH IS BEING LOOOKED AT
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10350
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.