Go Back  Xtreme Visual Basic Talk > General Discussion > Tech Discussions > I need help with Implements


Reply
 
Thread Tools Display Modes
  #1  
Old 08-30-2004, 10:37 AM
KentLam KentLam is offline
Newcomer
 
Join Date: Aug 2004
Posts: 3
Default 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
Reply With Quote
  #2  
Old 08-30-2004, 11:36 AM
lebb's Avatar
lebb lebb is offline
Disillusioned Code Poet

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
Default

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.
Reply With Quote
  #3  
Old 08-30-2004, 12:46 PM
KentLam KentLam is offline
Newcomer
 
Join Date: Aug 2004
Posts: 3
Default

Exactly what you meant, too bad VB doesn't support that. Hmm, I gotta think of something else. Thanks for your response.
Reply With Quote
  #4  
Old 08-30-2004, 02:24 PM
lebb's Avatar
lebb lebb is offline
Disillusioned Code Poet

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
Default

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.
Reply With Quote
  #5  
Old 08-30-2004, 02:38 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

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
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb

Last edited by Mike Rosenblum; 08-30-2004 at 05:41 PM.
Reply With Quote
  #6  
Old 08-30-2004, 05:31 PM
KentLam KentLam is offline
Newcomer
 
Join Date: Aug 2004
Posts: 3
Default

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.
Reply With Quote
  #7  
Old 08-30-2004, 05:39 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Four years of Java? VB 6 would be a big step back for you. You'll find that VB.Net borrowed a ton from Java. So, yes, I definately think you should give .Net a look...

You may find these links of interest btw:

(1) Basic Inheritance in VB.Net
(2) VB.Net Tutors Corner
(3) VB.Net Code Library

-- Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb

Last edited by Mike Rosenblum; 08-30-2004 at 05:47 PM.
Reply With Quote
  #8  
Old 08-30-2004, 06:13 PM
lebb's Avatar
lebb lebb is offline
Disillusioned Code Poet

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->