What is the deal with enum types and VB script?

What is the deal with enum types and VB script? I have a pre-.NET application with some APIs that take an enum type. Every thing works fine when calling the APIs from a VB app, but when I try to pass in enum types using VB Script (inside an ASP page for example) I have problems. I can replace the enum types with there integer values and everything works fine, but I would like to use my documented enum types.

I would like to know, is this a known problem and if so is there a work around other then substituting integer equivalents?
LVL 1
bdcAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mdouganConnect With a Mentor Commented:
You're right, I thought you were having difficulty using the enums in a particular ASP project, and I was offering things to try.  I don't have access to the code where we'd managed to expose the enums, but I'd remembered that it was possible.  A quick search of the Microsoft site provides this "proof".

HOWTO: Expose and Use ENUMS from Visual Basic Components in Active Server Pages (Q261250)

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q261250

0
 
rspahitzCommented:
I haven't worked with VB Script and enums, but if the enum is not public, other objects can't reference it.  Maybe VBScript can't access it for other reasons.

You can try copy/paste of the enum definition into the top of the VBScript to see it that helps.
0
 
ShaneCourtrilleCommented:
AFAIK enums don't work in ASP.  Probably because everything is a variant.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rspahitzCommented:
Enums are just an organized list of constants.  I'd be surprised if constants don't work in ASP, although that's also a Microsoft creation so you never know!

Well, if worse comes worst, you can always define the constants as variables, and place them in a separate insert-file.
0
 
mdouganCommented:
Enums do work in ASP, but, I think most people use CreateObject in ASP which is "late binding", so, if your enums are defined inside of your object, then you wont have an early binding reference to the object and it's enum values.

As rsPahitz suggests, you can either place them in a separate Include file so that you're re-defining the Enums inside of the script.  Or... I seem to remember being able to qualify enums in the VBScript and getting it to work.  Like:

If x = myObj.UPDATEMODE

Where UPDATEMODE was one of the values in the ENUM which is defined in the DLL pointed to by an object instance of the dll.
0
 
bdcAuthor Commented:
mdougan - Are you saying that if I use CreateObject I do not have accesses to enums that are part of the object I created?
0
 
mdouganCommented:
Well, think about it.  In regular VB, if you add a reference to a DLL to your project, then VB can look inside of that DLL for Enums, so, any reference to those enums in the code will be understood, because VB can look up the enums through all of the referenced libraries.

But, if you are doing a CreateObject in ASP, ASP has no idea where those enums are defined, unless you tell it.  

I suspect that you don't have access to enums that are part of the object you created unless you qualify the enum, and here is where I'm a little fuzzy, either with the name of the object variable, or perhaps with the name of the class.  So, let's say that your class was named clsUpdate and you had some code like:

Dim x

   Set x = CreateObject("myDLL.clsUpdate")

Then, I think that one of these would work
   if Mode = x.EXCLUSIVEMODE Then
   if Mode = clsUpdate.EXCLUSIVEMODE

Where mode is some local variable being compared against the enum EXCLUSIVEMODE in the DLL.

Now, I seem to remember doing this, but, it's possible that I'm confusing this with some other problem we had to solve.  If so, then you can either declare the same enums in your ASP script as exist in your DLL, and then it will at least appear as if the code recognizes the enums from the DLL, or, in the worst case scenario, if the ASP is not letting you declare enums, you can declare them as const and get the same effect.
0
 
bdcAuthor Commented:
I understand what you are saying, but it comes back to my original question. I have created an API that takes an enum as one of its parameters. For example in VB I can write:
InPlaceControl.SetState( kEnumOne, True)

Why can’t I do the following using VB script:
InPlaceControl.SetState EnumType.kEnumOne, True

BTW- I am creating the objects in the HTML using the GUID like so:
<object
   id="EnumType" classid="clsid: 00000000-0000-0000-0000-000000000000"
   codebase="program.cab"
   width=0 height=0>
  </OBJECT>

  <object
   id="AvViewX1_DWG" classid="clsid:00000000-0000-0000-0000-000000000000"
   codebase="program.cab"
   width=200 height=200>
   <param name="par"    value="val">
  </OBJECT>

I am not sure if that makes a difference. Maybe I am wrong, but I don’t see much of difference between the above and CreateObject.

Anyway, I am not able to make the VB Script work. I want to know if this is a known problem or am I doing something wrong?


0
 
mdouganCommented:
Well, what you are trying:
InPlaceControl.SetState EnumType.kEnumOne, True
is along the line of what I was suggesting about qualifying the enum.  

If this is not working for you, the first thing I'd try is to use CreateObject instead of referencing it through the HTML.  I don't know why it would make a difference, but in these things, it doesn't hurt to try all available possibilities.

Lastly, ASP is not a perfect world.  There are a lot of compromises.  I like the idea of using enums as parameters, and that will make it nicer when calling the component from VB or other VB based components.  But, if you can't get ASP to recognize the enums, then, like I said, you can duplicate the enum definition in the ASP and while you'll have to maintain the enum in two places, at least your code readability will benefit from it.
0
 
bdcAuthor Commented:
I don’t think you (mdougan) understand the question. I am the writer of the API that I will soon release to my users. I am not looking for tips on how to debug my situation. I am looking for confirmation on my situation, for the purpose of documentation. ShaneCourtrille said that enums don’t work. This is the confirmation that I am looking for, you said that enums do work. It looks like the burden of proof is on you.
0
 
DanRollinsCommented:
Hi bdc,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept mdougan's comment(s) as an answer.

bdc, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
bdcAuthor Commented:
I am still waiting for an answer. ShaneCourtrille said that enums don’t work and mdougan said they do, but does not know how.
0
 
DanRollinsCommented:
After 8 months, it becomes unlikely that you will get a definitive answer.  Please try to finalize the question.  If you want to split the points or delete the question, then please post a new comment with that decision.
-- Dan
0
 
bdcAuthor Commented:
How do I split the points?
0
 
DanRollinsCommented:
The normal way to split points is to post a 0-pt question to Community Support so that a Moderator will do it.  However, this question is already in the cleanup queue, so if you want to split the points, just add a new comment describing what you want to do, and a Moderator will handle it within about a week.
-- Dan
0
 
bdcAuthor Commented:
Can the moderator split the points 75 to ShaneCourtrille and 75 to mdougan?

Thanks
0
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

ShaneCourtrille, points for you at:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20463694.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.