 |
 |

08-30-2004, 10:37 AM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 3
|
|
I need help with Implements
|
Hi everyone,
I am pretty new to VB. I'm more of a Java programmer, so I am a little lost to the way VB uses Implements.
I need to know if it's possible to "Implements" a class with abstract functions as well as concrete functions. I can Implements a class with all abstract functions, that's simple, but I need some concrete functions in that class as well.
Please help asap, thanks in advance.
-Kent
|
|

08-30-2004, 11:36 AM
|
 |
Disillusioned Code Poet
Retired Moderator * Guru *
|
|
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
|
|
|
You mean your interface class would have some concrete functions that would get inherited? No, VB6 doesn't support that. If I've misunderstood your question, please clarify.
|
__________________
Laura
Ita erat quando hic adveni.
|

08-30-2004, 12:46 PM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 3
|
|
|
Exactly what you meant, too bad VB doesn't support that. Hmm, I gotta think of something else. Thanks for your response.
|
|

08-30-2004, 02:24 PM
|
 |
Disillusioned Code Poet
Retired Moderator * Guru *
|
|
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
|
|
|
If you need true inheritance, you should probably consider VB.NET. If that's not an option, feel free to share the specifics of your need and we can probably help with a workaround.
|
__________________
Laura
Ita erat quando hic adveni.
|

08-30-2004, 02:38 PM
|
 |
Microsoft Excel MVP
Forum Leader * Guru *
|
|
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
|
|
Edit: LOL, too slow again... I'm two for two today, L!  Using Implements in VB6 basically provides Properties, Functions, and Subs in an abstract manner only. However, you can make it fairly concrete rapidly by passing in an Instance of the Implemented Class and rely on the functionality therein...
As an example, IClass could look something like this:
Code:
' --------------------------------------------
' IClass
Option Explicit
Property Get MyType() As String
MyType = TypeName(Me)
End Property
Sub SomeMethod()
MsgBox "SomeMethod() Called"
End Sub
While clsMyClass could Implement IClass using something like this:
Code:
' --------------------------------------------
' clsMyClass
Option Explicit
Implements IClass
Dim m_IClass As IClass
' --------------------------------------------
' pvtInit() acts as Contructor:
Friend Function pvtInit(oIClass As IClass) As clsMyClass
Set m_IClass = oIClass
Set pvtInit = Me
End Function
' --------------------------------------------
' IClass Implementation (Required):
Private Property Get IClass_MyType() As String
IClass_MyType = m_IClass.MyType
End Property
Private Sub IClass_SomeMethod()
Call m_IClass.SomeMethod
End Sub
' --------------------------------------------
' Exposed as clsMyClass members (Optional):
Property Get MyType() As String
MyType = m_IClass.MyType
End Property
Sub SomeMethod()
Call m_IClass.SomeMethod
End Sub
I realize that this is fairly crude compared to a real OOP language, but I think this kinda gets you there (unless I didn't understand what you meant?).
Btw, if you're comfortable with Java, I think you'd likely like VB.Net a lot...
-- Mike
|
Last edited by Mike Rosenblum; 08-30-2004 at 05:41 PM.
|

08-30-2004, 05:31 PM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 3
|
|
Quote:
|
Originally Posted by Mike_R
Edit: LOL, too slow again... I'm two for two today, L!  Using Implements in VB6 basically only provides Properties, Functions, and Subs in an abstract manner only. However, you can make it fairly concrete rapidly by passing in an Instance of the Implemented Class and rely on the functionality therein...
As an example IClass could look something like this:
Code:
' --------------------------------------------
' IClass
Option Explicit
Property Get MyType() As String
MyType = TypeName(Me)
End Property
Sub SomeMethod()
MsgBox "SomeMethod() Called"
End Sub
While clsMyClass could Implement IClass using something like this:
Code:
' --------------------------------------------
' clsMyClass
Option Explicit
Implements IClass
Dim m_IClass As IClass
' --------------------------------------------
' pvtInit() acts as Contructor:
Function pvtInit(oIClass As IClass) As clsMyClass
Set m_IClass = oIClass
Set pvtInit = Me
End Function
' --------------------------------------------
' IClass Implementation (Required):
Private Property Get IClass_MyType() As String
IClass_MyType = m_IClass.MyType
End Property
Private Sub IClass_SomeMethod()
Call m_IClass.SomeMethod
End Sub
' --------------------------------------------
' Exposed as clsMyClass members (Optional):
Property Get MyType() As String
MyType = m_IClass.MyType
End Property
Sub SomeMethod()
Call m_IClass.SomeMethod
End Sub
I realize that this is fairly crude compared to a real OOP language, but I think this kinda gets you there (unless I didn't understand what you meant?).
Btw, if you're comfortable with Java, I think you'd likely like VB.Net a lot...
-- Mike
|
Thank you Mike and Lebb for your responses.
VB was actually one of the first PL I learned in high school.
Went I got to college, all they had was Java, and so four years of Java and nearly forgot everything about VB. Do you think VB.Net is a good choice for me? I've considered it, but haven't really look into it. I'll check it out sometimes this week. Thanks for the pointer.
|
|

08-30-2004, 05:39 PM
|
 |
Microsoft Excel MVP
Forum Leader * Guru *
|
|
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
|
|
Last edited by Mike Rosenblum; 08-30-2004 at 05:47 PM.
|

08-30-2004, 06:13 PM
|
 |
Disillusioned Code Poet
Retired Moderator * Guru *
|
|
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
|
|
|
Likewise, if you've enjoyed Java, you might want to give C# a try, since it has mostly Java syntax but is otherwise extremely similar to VB.NET.
|
__________________
Laura
Ita erat quando hic adveni.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|