469,631 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

How to initialize a struct in the declaration statement?

I declared a UDT...

Structure TeamRankingsStruc

Public intRankings() As Int16 ' The dimension must be omitted in the
context of a data type definition

Public strName As String

End Structure

I want to initialize it in the declaration statement...

Dim objRankings( ) As TeamRankingsStruc = {???}

What's the syntax? I've tried every combination of braces and parens that I
can think of.

Thanks!

Bill Nicholson

Cincinnati, OH USA

Nov 20 '05 #1
5 16760
"Bill Nicholson" <ph***@email.com> schrieb
I declared a UDT...

Structure TeamRankingsStruc

Public intRankings() As Int16 ' The dimension must be omitted in
the
context of a data type definition

Public strName As String

End Structure

I want to initialize it in the declaration statement...

Dim objRankings( ) As TeamRankingsStruc = {???}

What's the syntax? I've tried every combination of braces and parens
that I can think of.

Dim objRankings( ) As TeamRankingsStruc = {new TeamRankingsStruc, new
TeamRankingsStruc}

You could alo add a constructor to the structure:

Public Sub New(ByVal UBound As Integer)
ReDim intRankings(UBound)
End Sub

Dim objRankings( ) As TeamRankingsStruc = _
{new TeamRankingsStruc(5), new TeamRankingsStruc(10)}
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Thank You, but this does not initialize the individual data structures in
the array, instead it establishes a size for the array of structures.

I want to do something like this...

Dim objRankings( ) As TeamRankingsStruc = {(1, "Indiana"), (2, "Ohio
State"), (3, "Purdue")}

Regards,

Bill

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"Bill Nicholson" <ph***@email.com> schrieb
I declared a UDT...

Structure TeamRankingsStruc

Public intRankings() As Int16 ' The dimension must be omitted in
the
context of a data type definition

Public strName As String

End Structure

I want to initialize it in the declaration statement...

Dim objRankings( ) As TeamRankingsStruc = {???}

What's the syntax? I've tried every combination of braces and parens
that I can think of.

Dim objRankings( ) As TeamRankingsStruc = {new TeamRankingsStruc, new
TeamRankingsStruc}

You could alo add a constructor to the structure:

Public Sub New(ByVal UBound As Integer)
ReDim intRankings(UBound)
End Sub

Dim objRankings( ) As TeamRankingsStruc = _
{new TeamRankingsStruc(5), new TeamRankingsStruc(10)}
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Nov 20 '05 #3
* "Bill Nicholson" <ph***@email.com> scripsit:
Thank You, but this does not initialize the individual data structures in
the array, instead it establishes a size for the array of structures.

I want to do something like this...

Dim objRankings( ) As TeamRankingsStruc = {(1, "Indiana"), (2, "Ohio
State"), (3, "Purdue")}


\\\
Dim atrs() As TeamRankingsStruc = {New TeamRankingsStruc(1, "NY"), New TeamRankingsStruc(2, "Foo")}
..
..
..
Public Structure TeamRankingsStruc
Public Sub New(ByVal Rank As Integer, ByVal Name As String)
Me.Rank = Rank
Me.Name = Name
End Sub

Public Rank As Integer
Public Name As String
End Structure
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
"Bill Nicholson" <ph***@email.com> schrieb

Dim objRankings( ) As TeamRankingsStruc = {new TeamRankingsStruc,
new TeamRankingsStruc}

You could alo add a constructor to the structure:

Public Sub New(ByVal UBound As Integer)
ReDim intRankings(UBound)
End Sub

Dim objRankings( ) As TeamRankingsStruc = _
{new TeamRankingsStruc(5), new TeamRankingsStruc(10)}


Thank You, but this does not initialize the individual data
structures in the array, instead it establishes a size for the array
of structures.

I want to do something like this...

Dim objRankings( ) As TeamRankingsStruc = {(1, "Indiana"), (2,
"Ohio State"), (3, "Purdue")}

Add another parameter to the constructor:

Public Sub New(ByVal UBound As Integer, Name as string)
ReDim intRankings(UBound)
Me.strName = Name
End Sub

Dim objRankings( ) As TeamRankingsStruc = _
{New TeamRankingsStruc (1, "Indiana"), _
New TeamRankingsStruc (2, "Ohio State"), _
New TeamRankingsStruc (3, "Purdue")}
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
Perfect! Thanks again!

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"Bill Nicholson" <ph***@email.com> schrieb

Dim objRankings( ) As TeamRankingsStruc = {new TeamRankingsStruc,
new TeamRankingsStruc}

You could alo add a constructor to the structure:

Public Sub New(ByVal UBound As Integer)
ReDim intRankings(UBound)
End Sub

Dim objRankings( ) As TeamRankingsStruc = _
{new TeamRankingsStruc(5), new TeamRankingsStruc(10)}


Thank You, but this does not initialize the individual data
structures in the array, instead it establishes a size for the array
of structures.

I want to do something like this...

Dim objRankings( ) As TeamRankingsStruc = {(1, "Indiana"), (2,
"Ohio State"), (3, "Purdue")}

Add another parameter to the constructor:

Public Sub New(ByVal UBound As Integer, Name as string)
ReDim intRankings(UBound)
Me.strName = Name
End Sub

Dim objRankings( ) As TeamRankingsStruc = _
{New TeamRankingsStruc (1, "Indiana"), _
New TeamRankingsStruc (2, "Ohio State"), _
New TeamRankingsStruc (3, "Purdue")}
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ramprasad A Padmanabhan | last post: by
19 posts views Thread by Russell Shaw | last post: by
36 posts views Thread by Eric Laberge | last post: by
6 posts views Thread by sunny | last post: by
1 post views Thread by westlaker | last post: by
5 posts views Thread by Bob Altman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.