473,326 Members | 2,076 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,326 software developers and data experts.

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 17347
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ramprasad A Padmanabhan | last post by:
I have a simple structure defined like this struct userid { char uid; int insize; int outsize; }; typedef struct userid user;
19
by: Russell Shaw | last post by:
Hi, I have two structs in a header file, and they reference each other, causing a compile error. Is there a standard way to deal with this? typedef struct { ... RtAction *actions; }...
36
by: Eric Laberge | last post by:
Hi! I'm working on automatically generated code, and need to assign arrays. memcpy is an obvious solution, but it becomes complicated to use in the context I'm working on, ie.: I could use it...
16
by: Chad | last post by:
How do I set the value of a = 3 in the following lines of code? #include <stdio.h> struct letter{ char a; }; struct add { struct letter addit;
10
by: wenmang | last post by:
hi, I have following: struct array1 { int id; char *name; }; struct array2 {
6
by: sunny | last post by:
Hi All why does forward declaration does not work in following code. struct A; struct B { struct A a; // struct A *a // WORKS SINCE ITS POINTER
18
by: Ehud Shapira | last post by:
Is it possible to have a declaration of a struct pointer initialized to an unnamed struct? (I'm only concerned with static/global variables, if it matters.) I'm trying to do something like: ...
1
by: westlaker | last post by:
The declaration is: 1 2 struct ListNode; 3 typedef struct ListNode *Position; 4 typedef Position List; 5 struct HashTbl; 6 typedef struct HashTbl *HashTable; 7 8 struct...
5
by: Bob Altman | last post by:
Hi all, Here's a really basic C++ syntax question: How do I initialize an array, whose size is a literal, to all zeros in its initializer without coding a loop to do it? For example: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.