Solved

Interface confusion

Posted on 2001-06-13
19
157 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
 
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
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.

 
LVL 38

Accepted Solution

by:
PaulHews earned 50 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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

15 Experts available now in Live!

Get 1:1 Help Now