|
-
May 16th, 2004, 09:04 AM
#1
Thread Starter
Hyperactive Member
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
-
May 16th, 2004, 09:52 AM
#2
you need to declare the Structures ( as you would if they were in your own form's class ) eg:
VB Code:
Public Class TestIt
Public Sub RunTest()
Dim ST As New StructTest.ClientInfo '/// declare the structure of the class , rather than the Class it's self
ST.HomeAddress = "here"
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
~
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]
-
May 17th, 2004, 04:25 AM
#3
Retired VBF Adm1nistrator
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]
-
May 17th, 2004, 04:35 AM
#4
Thread Starter
Hyperactive Member
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?
-
May 17th, 2004, 04:38 AM
#5
Retired VBF Adm1nistrator
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|