LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2005, 04:48 PM   #1
ashirazi
Member
 
Registered: Jul 2004
Posts: 60

Rep: Reputation: 15
Polymorphism in VBA


Polymorphism in VBA

Hey everyone,

Ive been given the daunting task on creating a macro in MS Excel. I know VBA is probably the least favorite and most unsuitable for this forum, but I would greatly appreciate your help.

The problem is that I want to implement interfaces, but for some reason the compile just doesn’t take it, and spits out an error saying the function in the interface is not implemented. Here’s my code:


clsInterface
Code:
public sub run()
end sub

clsDerived
Code:
Implements clsInterface

Public Sub Class_Initialize()
    MsgBox "in derived"
End Sub

Public sub run() 
    MsgBox "Please work"
End sub

ThisWorkbook
Code:
    Dim cls As clsInterface
    Dim derived As clsDerived
    
    Set cls = New clsInterface
    Set derived = new clsDerived
    Set cls = derived
Ive wrecked my brains on this for hours and have not figured out why i get the error. Again, the error is: "Object module needs to implement 'run' for interface clsInterface

Thanks a million
raven
 
Old 07-01-2005, 07:41 PM   #2
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
If memory serves me correctly, in VB6, don't you need to implement classes like:

clsInterface
Code:
public sub run()
end sub
clsDerived
Code:
Implements clsInterface

Public Sub Class_Initialize()
    MsgBox "Class_Initialize"
End Sub

Private Sub clsInterface_run() 
    MsgBox "clsInterface_run"
End Sub
 
Old 07-05-2005, 03:27 PM   #3
ashirazi
Member
 
Registered: Jul 2004
Posts: 60

Original Poster
Rep: Reputation: 15
Thanks for the reply, appreciate it.

I do have one more question though, do you know if inheritance is possible in VBA? I basically have on class with the basic functionality and I want the rest of the classes to utilize it.

Thanks
 
Old 07-05-2005, 04:20 PM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Nope. Real inheritence isn't possible in VBA. At least not in VB6 style VBA. I believe VB.Net added inheritance along with many other features, though. It is one of many reasons I hate VB6.
 
Old 07-05-2005, 04:44 PM   #5
ashirazi
Member
 
Registered: Jul 2004
Posts: 60

Original Poster
Rep: Reputation: 15
Sucks!!!!!

Thanks anyway
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
ZSNES and VBA -- no sound Shafted Linux - Software 1 03-24-2005 01:05 PM
Error compiling VBA "Cannot find libPng" dustin_wielenga Linux - General 1 03-06-2005 02:39 AM
polymorphism in java jwn7 Programming 4 11-17-2004 04:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration