Solved

Interface confusion

Posted on 2001-06-13
19
158 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 55
Windows Script Host failed (Access is denied.) error 6 109
Access Object Property from VBA Module in Excel 2010 2 27
Help me. 3 46
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now