Re: Implements statement question
From: Fie Fie Niles (fniles_at_wincitesystems.com)
Date: 08/24/04
- Next message: AustinMN: "Re: unloading all forms.."
- Previous message: User: "Re: Need help : Optimize ODBC for fast MSAccess transaction"
- In reply to: Larry Serflaten: "Re: Implements statement question"
- Next in thread: Larry Serflaten: "Re: Implements statement question"
- Reply: Larry Serflaten: "Re: Implements statement question"
- Messages sorted by: [ date ] [ thread ]
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
>
>
- Next message: AustinMN: "Re: unloading all forms.."
- Previous message: User: "Re: Need help : Optimize ODBC for fast MSAccess transaction"
- In reply to: Larry Serflaten: "Re: Implements statement question"
- Next in thread: Larry Serflaten: "Re: Implements statement question"
- Reply: Larry Serflaten: "Re: Implements statement question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|