|
-
Aug 22nd, 2003, 02:13 PM
#1
Thread Starter
Lively Member
Large Class
I want to create a class where I can specify multiple properties or variables under different sections. Like:
VB Code:
Dim MyClass As New CustomClass
MyClass.Part1.ValueA = "123"
MyClass.Part1.ValueB = "321"
MyClass.Part2.ValueA = "abc"
MyClass.Part2.ValueA = "cba"
How can I accomplish this?
-
Aug 22nd, 2003, 02:23 PM
#2
Fanatic Member
Sounds like you might want to create child objects or child collections to hold the values.
-
Aug 22nd, 2003, 02:24 PM
#3
Hyperactive Member
Re: Large Class
Originally posted by Spyle
I want to create a class where I can specify multiple properties or variables under different sections. Like:
VB Code:
Dim MyClass As New CustomClass
MyClass.Part1.ValueA = "123"
MyClass.Part1.ValueB = "321"
MyClass.Part2.ValueA = "abc"
MyClass.Part2.ValueA = "cba"
How can I accomplish this?
If I understand your question right, I would say use structures..
VB Code:
Public Class CustomClass
Public Part1 As S_Part1
Public Part2 As S_Part2
Public Structure S_Part1
Public ValueA As Object
Public ValueB As Object
End Structure
Public Structure S_Part2
Public ValueA As Object
Public ValueB As Object
End Structure
End Class
Last edited by Hinder; Aug 22nd, 2003 at 02:27 PM.
-
Aug 22nd, 2003, 02:29 PM
#4
Thread Starter
Lively Member
-
Aug 22nd, 2003, 03:47 PM
#5
Hyperactive Member
Should those structures be declared inside the class or outside?
-
Aug 22nd, 2003, 03:59 PM
#6
Hyperactive Member
They can be declares either inside or out, Inside keeps the scope only inside the class, outside lets you declare an instance anywhere.. If that class is the only thing using it, why not encapsulate it...
-
Aug 22nd, 2003, 04:26 PM
#7
Another tidbit of info is that a nested class can access private members of its parent class. Although they must be shared since there is no real hierarchy created through nesting.
VB Code:
Public Class MyParent
Private Shared Common As String="Something"
Public Class MyNested
Public Function GetCommon() As String
Return MyParent.Common
End Function
End Class
End Class
-
Aug 22nd, 2003, 06:44 PM
#8
Addicted Member
i hav a little of modification on hinder's thing:
Code:
Public Class CustomClass
Public Part1 As S_Part
Public Part2 As S_Part
Public Structure S_Part
Public ValueA As Object
Public ValueB As Object
End Structure
End Class
as it seems for me Part1 and Part2 are of the same type,
so y declare two different structures ??
-
Aug 23rd, 2003, 07:31 PM
#9
he prolly just made a quick example.
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
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
|