Does anyone know if it is possible to initialise a structure array at
run-time, something like this:
<code>
Structure struct
Dim a As String
Dim b As Integer
Dim c As [Delegate]
End Structure
....
Dim st() As struct = {"1", 2, AddressOf Foo1}, _
{"2", 2, AddressOf Foo2}
</code>
I realise that this syntax is incorrect, but is there a syntax for this type
of initialisation?
TIA
Charles 2 7211
Here's one way - you could provide a constructor to initialize the values of
the structure. Something like this:
Structure struct
Dim a As String
Dim b As Integer
Dim c As [Delegate]
Public Sub New(ByVal a As String, ByVal b As Integer, ByVal c As
[Delegate])
a = a
b = b
c = c
End Sub
End Structure
Then initialize the structures as:
Dim st() As Struct = {New Struct("1", 2, AddressOf foo1), _
New Struct("2", 2, AddressOf foo2)}
hope that helps..
Imran.
"Charles Law" <bl***@nowhere. com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. Does anyone know if it is possible to initialise a structure array at run-time, something like this:
<code> Structure struct Dim a As String Dim b As Integer Dim c As [Delegate] End Structure
...
Dim st() As struct = {"1", 2, AddressOf Foo1}, _ {"2", 2, AddressOf Foo2} </code>
I realise that this syntax is incorrect, but is there a syntax for this
type of initialisation?
TIA
Charles
Hi Imran
Funnily enough, I have just been turning it over in my mind, and had
wondered if that might work. Thanks for confirming it. I suppose it is quite
elegant too, but I wonder if there is a way to do it without the New
keyword.
Charles
"Imran Koradia" <no****@microso ft.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. .. Here's one way - you could provide a constructor to initialize the values of the structure. Something like this:
Structure struct Dim a As String Dim b As Integer Dim c As [Delegate] Public Sub New(ByVal a As String, ByVal b As Integer, ByVal c As [Delegate]) a = a b = b c = c End Sub End Structure
Then initialize the structures as:
Dim st() As Struct = {New Struct("1", 2, AddressOf foo1), _ New Struct("2", 2, AddressOf foo2)}
hope that helps.. Imran.
"Charles Law" <bl***@nowhere. com> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. Does anyone know if it is possible to initialise a structure array at run-time, something like this:
<code> Structure struct Dim a As String Dim b As Integer Dim c As [Delegate] End Structure
...
Dim st() As struct = {"1", 2, AddressOf Foo1}, _ {"2", 2, AddressOf Foo2} </code>
I realise that this syntax is incorrect, but is there a syntax for this type of initialisation?
TIA
Charles
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stuart Norris |
last post by:
Dear Readers,
I am attempting to initialise a struct contiaing a dynamic character
string. In the example below I am trying to initialise the name field
so that my struct does not waste space. I know if I change char
name this will work, but I will waste alot of space. (I am
learning so I want to learn the best way)
How can I define a struct the allows variable length character strings
in the
|
by: anonymous |
last post by:
Hi folks,
I am in a fix trying to copy data to an array which is member of a
structure. What I am doing right now is:
char array = {0,1,2,3,4,5,6,7};
memcpy(structure.array, array, 8);
Is there a nicer way of doing this in a single statement?
|
by: Leo Nunez |
last post by:
Hello!
I need copy from structure "A" to "B" that contains "strings" in a one line code.
Me problem like this :
typedef struct tHeader{
char field1;
char field2;
char field3;
|
by: Brett |
last post by:
I have created a structure with five fields. I then create an array of this
type of structure and place the structure into an array element. Say index
one. I want to assign a value to field3 of the structure inside the array.
When I try this, an error about late assignment appears. Is it possible to
assign a value to a structure field that is in an array?
I'm currently getting around the problem by creating a new structure, assign...
|
by: eBob.com |
last post by:
I have an array
Dim FileInfo(MaxFiles) As OFI
of Structure
Structure OFI 'OneFileInfo
Dim Displayed As Boolean
...
Dim Dirname As String
| |
by: balasam |
last post by:
Dear friend,
I am having Linux platform.I am declaring the array of
structure in one file and how can access the values of the array of
structure in another file.
Using " extern " ,to extern the structure but when i
access the values of the array of structure ,the compilers displays the
error message.
Program :
|
by: David Fort |
last post by:
Hi,
I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a
function provided in a DLL.
The function takes the address of a structure which it will fill in with
values.
I get an error:
----------------
An unhandled exception of type 'System.NullReferenceException' occured in
|
by: Phoenix |
last post by:
Hi Friends ,
Could anyone please help me to resolve the following issue :
I pass an array of structures to a dll written in VC++ 6.0 whih fills
it with data . The following works well for VB 6.0 but when I wrote
the same piece of code in VB 2005
the array of structures remained empty even after the API call :
I have a structure as follows :
|
by: ctj951 |
last post by:
I have a very specific question about a language issue that I was
hoping to get an answer to. If you allocate a structure that
contains
an array as a local variable inside a function and return that
structure, is this valid?
As shown in the code below I am allocating the structure in the
function and then returning the structure. I know if the structure
contained only simple types (int, float) this will work without
problems as you...
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |