|
-
May 19th, 2004, 11:57 AM
#1
Thread Starter
Frenzied Member
array of objects
Why won't this work?
VB Code:
<Serializable()> Friend Class ExportObject
Friend Groups() As [b]New[/b] Group
Friend Class Group
Friend GroupName As String
Friend Members() As Member
Friend Sub AddMember(ByVal Name As String, ByVal ID As String)
'make the members object array big enough
ReDim Members(Members.GetUpperBound(0) + 1)
Members(Members.GetUpperBound(0)).MemberName = Name
Members(Members.GetUpperBound(0)).MemberID = ID
End Sub
End Class
Friend Class Member
Friend MemberName As String
Friend MemberID As String
End Class
Friend Sub AddGroup(ByVal GroupName As String)
Try
'resize the group object array
ReDim Groups(Groups.GetUpperBound(0) + 1)
Groups(Groups.GetUpperBound(0)).GroupName = GroupName
Catch ex As System.NullReferenceException
'if this happens, the group object has not yet been initialized
ReDim Groups(0)
Groups(0).GroupName = GroupName
End Try
End Sub
End Class
It tells me that arrays can not be declared using "new"
How am I supposed to make an object array from one of my classes?
Thanks in advance,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 19th, 2004, 12:06 PM
#2
You will have to loop through each element and instantiate it.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 19th, 2004, 12:16 PM
#3
Thread Starter
Frenzied Member
And how do I do this if I do not know how many groups I will be creating?
Is there a way to create the element and instantiate it at the same time?
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 19th, 2004, 12:36 PM
#4
I would suggest that you use a collection class of some sort when you have an unknown number of elements.
Then you would just instantiate the element as you are adding it (or you can, anyway)
VB Code:
MyGroupCollection.Add(New Group())
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 19th, 2004, 12:59 PM
#5
Thread Starter
Frenzied Member
So I have to define the group as being a collection?
Could you demonstrate this for me... I'm not quite following what it is that you're trying to convey to me.
....
use the code I posted if you want... nothing fancy, just to give me an idea of what I need to do
....
Thanks again,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 19th, 2004, 01:21 PM
#6
Thread Starter
Frenzied Member
Nevermind...
I think I got it...
Good 'ol MSDN did it again... 
Thanks for the tip,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|