Solved

What is the deal with enum types and VB script?

Posted on 2002-04-12
17
402 Views
Last Modified: 2012-08-13
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?
0
Comment
Question by:bdc
  • 6
  • 4
  • 3
  • +3
17 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 6937239
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
 
LVL 1

Expert Comment

by:ShaneCourtrille
ID: 6937314
AFAIK enums don't work in ASP.  Probably because everything is a variant.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6937380
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
 
LVL 18

Expert Comment

by:mdougan
ID: 6937708
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
 
LVL 1

Author Comment

by:bdc
ID: 6942910
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
 
LVL 18

Expert Comment

by:mdougan
ID: 6943406
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
 
LVL 1

Author Comment

by:bdc
ID: 6943504
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
 
LVL 18

Expert Comment

by:mdougan
ID: 6943834
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Author Comment

by:bdc
ID: 6945559
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
 
LVL 18

Accepted Solution

by:
mdougan earned 75 total points
ID: 6946291
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7654027
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
 
LVL 1

Author Comment

by:bdc
ID: 7695263
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7697016
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
 
LVL 1

Author Comment

by:bdc
ID: 7698061
How do I split the points?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7698372
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
 
LVL 1

Author Comment

by:bdc
ID: 7698531
Can the moderator split the points 75 to ShaneCourtrille and 75 to mdougan?

Thanks
0
 

Expert Comment

by:SpideyMod
ID: 7755255
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

Featured Post

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.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 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

20 Experts available now in Live!

Get 1:1 Help Now