Resend my activation email : Register : Log in 
BCF: Bike Chat Forums


Programming: VB6/VBA

Reply to topic
Bike Chat Forums Index -> The Geek Zone
View previous topic : View next topic  
Author Message

Yoko
Brolly Dolly



Joined: 25 Feb 2007
Karma :

PostPosted: 13:54 - 09 Nov 2007    Post subject: Programming: VB6/VBA Reply with quote

Alright Very Happy

I'm trying to teach myself Interface Classes and Implementation in VB6/VBA and I cant quite get my head around it.

I'm reading about it in VBA Developers Handbook (By Ken Getz & Mike Gilbert) but its just not clicking in my head.

I've looked at sample code and read up about it but I cant find a simple explanation of it, how it works and the benefits.

So if any of you programmers out there have the answer please can you enlighten me!

Thumbs Up
____________________
Sheep Shagger
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

veeeffarr
Super Spammer



Joined: 22 Jul 2004
Karma :

PostPosted: 13:57 - 09 Nov 2007    Post subject: Reply with quote

Do you know the basics? If no, start there.

T
 Back to top
View user's profile Send private message You must be logged in to rate posts

Yoko
Brolly Dolly



Joined: 25 Feb 2007
Karma :

PostPosted: 14:06 - 09 Nov 2007    Post subject: Reply with quote

Well I know how to create a class with method, events and properties and how to interact with them etc.

I know that when you implement another class you are including its events, properties & methods in to the current class (though not the code, just the declarations)

Originally I thought that implementation is where you write some code in a class then if you write another class and want to import some of the methods, properties & events into your new class without rewriting the code.

I dont understand the benefits of just importing the declarations rather than the code as well.

The samples I've looked at talk about using callbacks instead of raising events but I dont understand how it works!
____________________
Sheep Shagger
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

TheShaggyDA
Repost Police



Joined: 14 Jun 2004
Karma :

PostPosted: 14:07 - 09 Nov 2007    Post subject: Reply with quote

I'm learning .NET at the mo, and one analogy of an interface class is to think of it as a car radio; although the radio has a pile of coils, chips, and other discrete components, the interface is the bit you interact with - the volume control, tuning knob and station buttons. It means that you don't have to care what is going on in the background, you just know that when you hit a station button, it'll go to that station.

From a DB perspective, it means that you can write a class the allows you to have fixed features - add, delete, change, lookup, without caring whether it's a flat ASCII file or Oracle database in the background.

This means that you write the interface and only specify what it can do, not how it does it. You then write another class that implements that interface.
____________________
Current: CB500 Previous: CB100N, CB250RS, XJ900F, GT550, GPZ750R/1000RX, AJS M16, R100RT, Enfield Bullet

[i:6e3bfc7581]But still I fear and still I dare not laugh at the madman...[/i:6e3bfc7581]
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

TheShaggyDA
Repost Police



Joined: 14 Jun 2004
Karma :

PostPosted: 14:09 - 09 Nov 2007    Post subject: Reply with quote

Yoko wrote:
I dont understand the benefits of just importing the declarations rather than the code as well.


It means your code is more maintainable. If you want to implement the same software on an Oracle database after originally being rolled out on SQL Server, you only have to change the "final" class in the chain, rather than everywhere that wants to access the data.
____________________
Current: CB500 Previous: CB100N, CB250RS, XJ900F, GT550, GPZ750R/1000RX, AJS M16, R100RT, Enfield Bullet

[i:6e3bfc7581]But still I fear and still I dare not laugh at the madman...[/i:6e3bfc7581]
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

Yoko
Brolly Dolly



Joined: 25 Feb 2007
Karma :

PostPosted: 14:18 - 09 Nov 2007    Post subject: Reply with quote

But isnt that what a class does anyway...

You write a class to do x, y and z then another programmer can just create an instance of your class, supply any parameters needed and it will do whatever I programmed it to do. That way he doesnt need to see what method x is doing, only knows that it is doing it...

If another programmer then implemented my class he'd see that it has x, y and z but not what I intended x, y and z to do...
____________________
Sheep Shagger
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

TheShaggyDA
Repost Police



Joined: 14 Jun 2004
Karma :

PostPosted: 14:21 - 09 Nov 2007    Post subject: Reply with quote

I think if it's a normal class, then you can choose which methods you want to inherit, whereas with an interface class you HAVE to implement all of its methods.
____________________
Current: CB500 Previous: CB100N, CB250RS, XJ900F, GT550, GPZ750R/1000RX, AJS M16, R100RT, Enfield Bullet

[i:6e3bfc7581]But still I fear and still I dare not laugh at the madman...[/i:6e3bfc7581]
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

Yoko
Brolly Dolly



Joined: 25 Feb 2007
Karma :

PostPosted: 14:28 - 09 Nov 2007    Post subject: Reply with quote

My simple example...

Class 1

Code:
Option Explicit

Public Sub x()
    MsgBox "Program x"
End Sub


Class 2

Code:
Option Explicit

Implements Class1

Private Sub Class1_x()
    MsgBox "Program x1"
End Sub

Public Sub y()
    Call Class1_x
End Sub


Std Module

Code:
Option Explicit

Dim p As Class1
Dim q As Class2

Sub a()
    Set p = New Class1
    p.x
End Sub

Sub b()
    Set q = New Class2
    q.y
End Sub


Sub a calls method x from class1
Sub b calls method y from class2 which implements class1

I would expect b to display a message box with "Program x" then another message box with "Program x1" but it does not. I only get one message box with "Program x1". Thats my interpretation of it.
____________________
Sheep Shagger
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

Yoko
Brolly Dolly



Joined: 25 Feb 2007
Karma :

PostPosted: 15:09 - 09 Nov 2007    Post subject: Reply with quote

Ah ha!!! The penny has just dropped. Very Happy

I didnt realise that you are meant to use an interface with more than one class.

Cool so I can write an interface and then two or more classes which have the same functions etc as my interface (or write two classes and a corresponding interface) I can then use either classes via the interface as opposed to instancing each class.
____________________
Sheep Shagger
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts
Old Thread Alert!

The last post was made 18 years, 357 days ago. Instead of replying here, would creating a new thread be more useful?
  Display posts from previous:   
This page may contain affiliate links, which means we may earn a small commission if a visitor clicks through and makes a purchase. By clicking on an affiliate link, you accept that third-party cookies will be set.

Post new topic   Reply to topic    Bike Chat Forums Index -> The Geek Zone All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Read the Terms of Use! - Powered by phpBB © phpBB Group
 

Debug Mode: ON - Server: birks (www) - Page Generation Time: 0.16 Sec - Server Load: 1 - MySQL Queries: 14 - Page Size: 64.61 Kb