Re: Implements statement question

From: Fie Fie Niles (fniles_at_wincitesystems.com)
Date: 08/24/04


Date: Tue, 24 Aug 2004 09:38:49 -0500

Thank you very much. I replace the code using Private mName As String in
clsCustomer. It works now.
You mentioned that "When used as an interface, you never add code like: Set
objData = New PersonalData", but I have
"Dim clsPer As New PersonalData" at the beginning of Form1, is this not good
?
Thank you.

Here are the codes:
Form1
   Dim clsPer As New PersonalData
   Dim clsCust As New Customer
   Dim str As String

   Set clsPer = clsCust
   clsPer.Address = "per address"
   clsPer.Name = "per name"
   MsgBox clsPer.Name & " " & clsPer.Address

   str = GetStr(clsPer)
   MsgBox str

Function GetStr(clsPD As PersonalData)
   GetStr = clsPD.Name & " " & clsPD.Address
End Function

clsCustomer
Implements PersonalData
Private mName As String
Private mAddress As String

Private Property Get PersonalData_Address() As String
   'PersonalData_Address = "CustomerAddress"
   PersonalData_Address = mAddress
End Property
Private Property Let PersonalData_Address(ByVal RHS As String)
   mAddress = RHS
End Property
Private Property Let PersonalData_Name(ByVal RHS As String)
   mName = RHS
End Property
Private Property Get PersonalData_Name() As String
   PersonalData_Name = mName
End Property

"Larry Serflaten" <serflaten@usinternet.com> wrote in message
news:%23gxa2fZiEHA.2448@TK2MSFTNGP12.phx.gbl...
>
> "Fie Fie Niles" <fniles@wincitesystems.com> wrote
> > Thank you everybody, but I am still confused. This is the first time I
am
> > using Implements.
> >
> > I tried the following code,and got Run-time error 91: object variable or
> > with block variable not set:
> >
> > Private Property Let PersonalData_Name(ByVal RHS As String)
> > PersonalData.Name = RHS -->> Run-time error 91: object variable or
with
> > block variable not set
> > End Property
> >
> > I implements PersonalData in class Customer.
>
> Then you need to create a private variable in your Customer class to
> hold the Name value:
>
> ' Memory for Name
> Private mName As String
>
> Private Property Let PersonalData_Name(ByVal RHS As String)
> mName = RHS
> End Property
>
> An interface is just window dressing, the class that implements the
> interface has to provide all the code. In this case it is very similar
> to a plain old property that you would supply the Let and Get accessors
> for. The difference is, that particular property is not available in your
> Customer class, except through the PersonalData interface. You can,
> if you want, provide Customer with its own Name property that uses
> the same mName private variable, but it is not required.
>
> Public Property Let Name(ByVal NewValue As String)
> mName = NewValue
> End Property
>
> (Ditto for the Get side too)
>
> The error you got was because PersonalData is not an object, it is
> being used as an interface. When used as an interface, you never
> add code like: Set objData = New PersonalData, and since you never
> create an object like that, you can't pull one out of thin air in your
> properties. For all intents and purposes, properties you add for the
> implemented interface are just like any other property on the class that
> you have to provide a private variable for.
>
> LFS
>
>



Relevant Pages

  • Re: OOP object collections
    ... interface for the business object. ... string ZebraName ... private System.DateTime _createDate; ... and a Employee class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: OOP object collections
    ... interface for the business object. ... string ZebraName ... private System.DateTime _createDate; ... and a Employee class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Implements statement question
    ... Then you need to create a private variable in your Customer class to ... Private mName As String ... An interface is just window dressing, ... Customer class, ...
    (microsoft.public.vb.general.discussion)
  • Re: Property Modified (dirty)
    ... Private Function PropertyIsDirty(_ ... Public Property FirstNameAs String ... Or maybe you could implement an interface to group all your ... > Public Property FirstNameAs String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MustInherit classes
    ... I have tried every combination I can think of using> Public, Private, Friend... ... > What I want to acheive is something like the below statements, without a> user being able to instantiate a MySecondClass on it's own. ... > Public Item1 As String ... I'm thinking this should> actually be an interface, but I am having problems building an interface> that will work with XML Serialization, which this class structure will need> to do. ...
    (microsoft.public.dotnet.framework)