Results 1 to 9 of 9

Thread: Large Class

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    69

    Large Class

    I want to create a class where I can specify multiple properties or variables under different sections. Like:

    VB Code:
    1. Dim MyClass As New CustomClass
    2.  
    3. MyClass.Part1.ValueA = "123"
    4. MyClass.Part1.ValueB = "321"
    5.  
    6. MyClass.Part2.ValueA = "abc"
    7. MyClass.Part2.ValueA = "cba"

    How can I accomplish this?

  2. #2
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Sounds like you might want to create child objects or child collections to hold the values.

  3. #3
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    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:
    1. Dim MyClass As New CustomClass
    2.  
    3. MyClass.Part1.ValueA = "123"
    4. MyClass.Part1.ValueB = "321"
    5.  
    6. MyClass.Part2.ValueA = "abc"
    7. MyClass.Part2.ValueA = "cba"

    How can I accomplish this?

    If I understand your question right, I would say use structures..


    VB Code:
    1. Public Class CustomClass
    2.  
    3.     Public Part1 As S_Part1
    4.     Public Part2 As S_Part2
    5.  
    6.     Public Structure S_Part1
    7.         Public ValueA As Object
    8.         Public ValueB As Object
    9.     End Structure
    10.  
    11.     Public Structure S_Part2
    12.         Public ValueA As Object
    13.         Public ValueB As Object
    14.     End Structure
    15.  
    16. End Class
    Last edited by Hinder; Aug 22nd, 2003 at 02:27 PM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    69
    Thank you!

  5. #5
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Should those structures be declared inside the class or outside?

  6. #6
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    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...

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. Public Class MyParent
    2.   Private Shared Common As String="Something"
    3.  
    4.   Public Class MyNested
    5.  
    6.       Public Function GetCommon() As String
    7.            Return MyParent.Common
    8.       End Function
    9.  
    10.   End Class
    11.  
    12. End Class

  8. #8
    Addicted Member
    Join Date
    Apr 2003
    Posts
    170
    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 ??

  9. #9
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    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
  •  



Click Here to Expand Forum to Full Width