By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,446 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

How to Initialise a Structure Array in a Dim Statement

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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****************@TK2MSFTNGP11.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

Nov 21 '05 #2

P: n/a
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****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.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****************@TK2MSFTNGP11.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


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.