Link to home
Start Free TrialLog in
Avatar of bdc
bdc

asked on

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?
Avatar of rspahitz
rspahitz
Flag of United States of America image

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.
Avatar of ShaneCourtrille
ShaneCourtrille

AFAIK enums don't work in ASP.  Probably because everything is a variant.
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.
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.
Avatar of bdc

ASKER

mdougan - Are you saying that if I use CreateObject I do not have accesses to enums that are part of the object I created?
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.
Avatar of bdc

ASKER

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?


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.
Avatar of bdc

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of mdougan
mdougan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DanRollins
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
Avatar of bdc

ASKER

I am still waiting for an answer. ShaneCourtrille said that enums don’t work and mdougan said they do, but does not know how.
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
Avatar of bdc

ASKER

How do I split the points?
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
Avatar of bdc

ASKER

Can the moderator split the points 75 to ShaneCourtrille and 75 to mdougan?

Thanks
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

ShaneCourtrille, points for you at:
https://www.experts-exchange.com/questions/20463694/points-for-ShaneCourtrille-re-20288065.html