Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Interface confusion

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
uron6342
Asked:
uron6342
  • 5
  • 5
  • 4
  • +3
1 Solution
 
PaulHewsCommented:
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
 
CJ_SCommented:
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
 
uron6342Author Commented:
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
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.

 
nutwissCommented:
yup...
0
 
anthonycCommented:
You can build a GetWeather function in CWeather, and then just have it call the IWeather_GetWeather
0
 
CJ_SCommented:
You cannot create an instance of an interface in ASP. That is way it does not work.

regards,
CJ
0
 
uron6342Author Commented:
is this the only way to do it, by calling IWeather_GetWeather ?

thanks - u
0
 
CJ_SCommented:
way -> why
0
 
CJ_SCommented:
Yes
0
 
PaulHewsCommented:
>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
 
uron6342Author Commented:
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
 
CJ_SCommented:
VB.Net will be able to do so indeed...the asp code will be written way different.
0
 
amebaCommented:
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
 
PaulHewsCommented:
And everything will be rosy :)
0
 
amebaCommented:
:-)

>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
 
PaulHewsCommented:
You can do that in VB, but not in ASP I think was the point.
0
 
amebaCommented:
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
 
PaulHewsCommented:
>I mixed vb, asp, aspx  :-)

S'OK, I do that all the time.  :)
0
 
amebaCommented:
:) I guess it's OK to be a bit confused - after all this question is - "Interface confusion"
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 5
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now