Need help with simple class

M

Miguel Dias Moura

Hello,

I created the class "document":

Public Class Document

Private Shared _title As String

Public Property Title() As String
Get
Return _title
End Get
Set(ByVal value As String)
If _title = value Then
Return
End If
_title = value
End Set
End Property

End Class

To set the property value I am using:

Dim MyDocument As New Document
MyDocument.Title = "My book title"

I need to be able to create "second level" properties. An example:

MyDocument.Author.Name = "Author Name"

Instead of having

MyDocument.AuthorName = "Author Name"

I inserted the class "Author", with property "Name" inside Class
Document.

It is not working. Could someone explain me how to create it?


Thank You,
Miguel
 
T

Trevor Benedict R

Declare a Public Variable of Type
Public Author as New Author and it shoule be available

Regards,
Trevor Benedict R
MCSD
 
T

tdavisjr

Looks like you need to create an Author Class that has a shared
property called Name which is a String
then,
In your Document class, create a Property with the name of Author that
returns a new Author object.

Therefore, you can access the the Name of the Author like:

MyDocument.Author.Name
 
T

tdavisjr

correction: The Name property in the Author class should not be shared
if the Author propety in the Document Class returns a new Author. You
can't access a shared Property if the object is an instance. Hope
that's not too complicated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top