Solved

Using interface as a variable type (sub parameter)

Posted on 2004-04-17
7
201 Views
Last Modified: 2010-04-24
I have an interface:

Public Interface jobDescription
    Sub ShowDuties()
End Interface

in Person.vb (class module) which is joined to my project by reference (.DLL)
The code for ShowDuties() is defined in several subclasses which inherit from the Person abstract class
So far there is no problem.

I am required to create a form level subroutine (in Form1.vb) as follows:
    Public Sub displayDuties(ByVal job As jobDescription)
         (bla bla bla)
    End Sub

the problem is that "jobDescription" in this sub is not recognised as a valid identifier. My notes state that the purpose of this function is to be able to call it using a variety of subclasses of Person, using the "jobDescription" interface to identify it, and then call the showDuties() subroutine (each one different) regardless of what type of Person was sent to displayDuties.
There is so much code I can't post it all here, but I hope you can get the general idea of what I need to do, and what the problem is, and how to fix it. I've spent hours searching through MSDN and can't find a single example of using an interface identifier as a variable type.
(I am using VB.NET, not 2003 or 2004)
thanks
Adam
0
Comment
Question by:adamjsawyerj
  • 3
  • 3
7 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 65 total points
ID: 10861492
An Interface is use in object-oriented program as a set of properties, methods, and events that are necessary to implement a certain type of functionality.  The IDisposable interface is an example, where you, if you implement all that is necessary will give you the functionality of being able to use the .Dispose method of an object to force garbage collection so that you can determine when it will occur.  You are mixing interfaces with just a base class and inheritance.

Bob
0
 

Author Comment

by:adamjsawyerj
ID: 10869463
I am not disputing that the information given was accurate, only that it was not relevant. I accepted the answer because there were no other answers to accept, and I didn't want the question drawn out after I had worked it out for myself. I mean no offense by the grade I gave, but stand by the grade because the answer given did not help me.
adam
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10870430
How did you work it out for yourself?

Bob
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:adamjsawyerj
ID: 10870570
   Public Sub displayDuties(ByVal job As persons.jobDescription)
      bla bla bla
    End Sub

I simply needed to prefix jobDescription with the base class containing the jobDescription interface. I didn't need to know about the theory of base classes or interfaces, just how to get the compiler to recognise my interface variable. I meant no offence by giving a low grade, but could hardly consider it a good answer when it was a large tangent from the given problem. I trust you will understand this. I did post a message explaining this at the time of grading, but it seems to have disappeared or not got there at all.
regards
adam
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10870593
No offense taken.  All grades of C need an explanation.  It is possible to make assumptions or incorrect guesses as to what people are talking about, which I certainly made in my case.  Also, programming is a continuously dynamic learning process, so I try to never take any hardline stances with anything.

Bob
0
 

Author Comment

by:adamjsawyerj
ID: 10870603
Looking back over my question, I can perhaps understand that I didn't give enough relevant information. Perhaps this led to the expert not fully understanding my problem. I apologise if this is the case, and if the grade should be changed then go ahead.
sorry
adam
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now