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

x
?
Solved

Interface confusion

Posted on 2001-06-13
19
Medium Priority
?
170 Views
Last Modified: 2010-05-02
hi-

i have an interface as follows (IWeatherManager.cls)

Option Explicit

Public Function GetWeather(strZipCode, strProxy) As Variant
End Function

I then have a class that implements it. (CWeatherManager.cls)

Option Explicit

Implements IWeatherManager


Public Function GetWeather(strZipCode, strProxy) As Variant

....

End Function


When i try to compile my dll I get an error message stating that CWeatherManager needs to implement IWeatherManager.GetWeather.

If if goto the drop down menu it offers the method name as

Public Function IWeatherManager_GetWeather(strZipCode As Variant, strProxy As Variant) As Variant

If i then implement this then it compiles fine.

Why can't i just name this method GetWeather?


Thanks - u

0
Comment
Question by:uron6342
  • 5
  • 5
  • 4
  • +3
19 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 6186569
That's just the way the syntax works.  I guess it also allows us to distinguish between interface elements and non-interface elements of a class.
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6186599
You need to implement all functions provided by the interface. The syntax of the function is in the way: INTERFACENAME_FunctionName(...). There is no way you can get over that.

regards,
CJ
0
 

Author Comment

by:uron6342
ID: 6186615
ok, according to my book, that is correct.

i wrote this test program which works.

Option Explicit

Private Sub Form_Load()

    Dim objWeatherManager As WeatherManager.CWeatherManager
    Dim objIWeatherManager As WeatherManager.IWeatherManager
   
    Set objWeatherManager = New WeatherManager.CWeatherManager
    Set objIWeatherManager = objWeatherManager
   
    Call objIWeatherManager.GetWeather("14450", "")

End Sub


however, i need this component to run from my asp page. but i get this error message.

Error Type:
Microsoft JScript runtime (0x800A01B6)
Object doesn't support this property or method
/admin/Weather.asp, line 36.

when i call the object directly rather than using the interface it works fine.
im not even sure where i should ask for help on this.

a code snippet is here.


var weatherManager;
                                   var iWeatherManager;
                                   var html;
                                   var PROXY = "cf2.cinops.foo.com";
         
                                   weatherManager = Server.CreateObject("WeatherManager.CWeatherManager");
                                   iWeatherManager = Server.CreateObject("WeatherManager.IWeatherManager");
                                   
                                   iWeatherManager = weatherManager
                                   
                                   html = String(iWeatherManager.GetWeather(Request.Form("txtLocation"),PROXY));
                                   Response.Write("Temp is " + html + " degrees");
                                   break;


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:nutwiss
ID: 6186624
yup...
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 6186625
You can build a GetWeather function in CWeather, and then just have it call the IWeather_GetWeather
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6186687
You cannot create an instance of an interface in ASP. That is way it does not work.

regards,
CJ
0
 

Author Comment

by:uron6342
ID: 6186690
is this the only way to do it, by calling IWeather_GetWeather ?

thanks - u
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6186691
way -> why
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6186705
Yes
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
ID: 6186727
>iWeatherManager = Server.CreateObject("WeatherManager.IWeatherManager");


You should never need to instantiate your interface.  It is an empty class.  In fact it is hard to see the advantage of using an interface at all in this case as the scripting language does not allow the early binding that would make use of it.

In VB, you would do this

Dim oWeatherManager as IWeathermanager

Then you could assign that variable an instance of your cWeatherManager class and use all the interface functions.  The advantage is that you can assign different classes to the same variable, but keep the speed of early binding by not declaring the variable as Object.  In the scripting language the variables are not typed, thus every binding is late binding, and there is no advantage to using an interface class.
0
 

Author Comment

by:uron6342
ID: 6186840
Yea, I see what you are saying Paul. I agree with everything you said. I never used to use interfaces for my web programming, but I just read "VB COM" and got a little excited.

So, I guess what I learned here is that I shouldn't use interfaces in this case. However, I am supposing this will be different when VB.Net comes out which I will be able to use in my ASPs then.


Thanks - u



0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6186868
VB.Net will be able to do so indeed...the asp code will be written way different.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6186902
Small note - do *not* change what you got in VB:

Private Function IWeatherManager_GetWeather(strZipCode As Variant, strProxy As Variant) As Variant
to:
Public Function IWeatherManager_GetWeather(strZipCode As Variant, strProxy As Variant) As Variant

Keep it Private!
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6186903
And everything will be rosy :)
0
 
LVL 15

Expert Comment

by:ameba
ID: 6186948
:-)

>So, I guess what I learned here is that I shouldn't use interfaces in this case

??? I think you should have learned how to use interface.
Or you are saying this doesn't work:

Dim oWeatherManager as IWeathermanager
Set oWeatherManager = Server.CreateObject("WeatherManager.clsWeatherManager");
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6186978
You can do that in VB, but not in ASP I think was the point.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6186992
Ouch, in ASP everything is Variant, so you cannot have this declaration:
Dim oWeatherManager as IWeathermanager

Sorry, sorry, ignore what I said - I mixed vb, asp, aspx  :-)
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6187008
>I mixed vb, asp, aspx  :-)

S'OK, I do that all the time.  :)
0
 
LVL 15

Expert Comment

by:ameba
ID: 6187031
:) I guess it's OK to be a bit confused - after all this question is - "Interface confusion"
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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

963 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