Results 1 to 5 of 5

Thread: Structure Question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    Structure Question

    I have a question about using Structures..


    Code:
    Public Class TestIt
    
        Public Sub RunTest()
    
            Dim ST As New StructTest
    
            ST.ClientInfo.???  'It wont let me access the structures members, why?
    
    
        End Sub
    
    End Class
    
    Public Class StructTest
    
        Public Structure ClientInfo
            Public Name As String
            Public HomeAddress As String
            Public Phone As String
        End Structure
    
        Public Structure ClientJobInfo
            Public Company As String
            Public CompanyAddress As String
            Public CompanyPhone As String
        End Structure
    
    End Class

    Why cant I access the structures members when I try to reference them from an instance of the StructTest class? They are all public.



    Hinder

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you need to declare the Structures ( as you would if they were in your own form's class ) eg:
    VB Code:
    1. Public Class TestIt
    2.  
    3.     Public Sub RunTest()
    4.  
    5.         Dim ST As New StructTest.ClientInfo '/// declare the structure of the class , rather than the Class it's self
    6.         ST.HomeAddress = "here"
    7.  
    8.     End Sub
    9.  
    10. End Class
    11. Public Class StructTest
    12.  
    13.     Public Structure ClientInfo
    14.         Public Name As String
    15.         Public HomeAddress As String
    16.         Public Phone As String
    17.     End Structure
    18.  
    19.     Public Structure ClientJobInfo
    20.         Public Company As String
    21.         Public CompanyAddress As String
    22.         Public CompanyPhone As String
    23.     End Structure
    24.  
    25. End Class
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I don't know why you would want to do it like that.
    I would either, use all of the properties from the Structures as properties of the class, or implement the structures as seperate classes and reference them from your main class.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Well I wouldn't mind making all the properties part of the class if I could split them up some how.. Basically I'm looking for a way to give a group of properties in a class a Namespace of some type.. So basically I would like to keep it a bit more organized.. If I have 100+ properties in one class.. I would like to break them up a bit.. Maybe there is a way to do this that I am unaware of that doens't require creating classes or structures inside the main class I'm building?

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Use classes then. Because if you use classes, you can pass that class to other DLLs or applications, whereas you cannot if you're using Structures. You can also use methods and events inside those classes if your application requires more functionality further down the road.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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