Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using interface as a variable type (sub parameter)

Posted on 2004-04-17
7
Medium Priority
?
209 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
6 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 130 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline

783 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