All Forums >> [Scripting] >> WSH & Client Side VBScript >> Accessing enumerated types from vbscript Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
I am integrating a third party COM component from pure vbscript. All is working fine and I can interact with the API successfully until I try to access some enumerated types.
e.g. ProWeb.engine = qasVerification
How can I specify the UUID so that my vbscript recognizes qasVerification. If this were ASP then I would do this as follows:
<!--METADATA NAME="QuickAddress Pro Web SOAP Proxy" TYPE="TypeLib" UUID="{42F6FD66-C030-4942-840C-58B939EAEDE0}"--> <%
Is there an equivalent to the above statement in pure vbscript?
As for a vbscript solution to Enumerating, I've seen an Enumerate() method floating around the web but I've never used it since I generally use JavaScript first for my projects. But here is what I've seen about this elusive idea:
I think the terms a little fuzzy. Enumerator = an Iterator. Enum = a Struct. You can create an Enumerator in vbscript to iterate through the contents of a collection. You can also create an Enumerator to iterate through the results of a Pull operation in ASP (the link that TNO provided). As far as I know however, neither VBScript nor JavaScript support Enums.
You are correct that Iterating relies on an index, so my description was not entirely precise. Regardless, there is a difference between an Enumerating a collection (To count or list one by one) vs. an Enumerated type (aka enum - A type which includes in its definition an exhaustive list of possible values for variables of that type).
At this point, it just seems to me like you guys are in a contest to see whose dictionary is toughest. Or possibly a forum-obfuscation contest? heh heh
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
After a bit more research I figured out what the difference was. So to get back to the subject at hand, ebgreen is right that vbscript doesn;t support enumerations. But JScript (ECMAScript Edition 4) DOES contain enum . So it MAY be possible through WSH. problem is I have yet to see a usage of enum outside of JScript .NET, so I'll have to dig around for a bit
_____________________________
To iterate is human, to recurse divine. -- L. Peter Deutsch
With that enum, in your code you could use TimeOfDay.Afternoon and the compiler would replace it with 1. Contrast that with implementing an enumerator. In C# when you do a foreach loop, it is simply shorthand for this code:
This code would enumerate through a collection of strings and DoSomething() with each one.
I think the first example (enum) is what the OP needs and is not supported in VBScript.
EDIT(EBGREEN): Corrected my code tag incompetence.
< Message edited by ebgreen -- 10/23/2006 8:42:01 AM >
I think we need another look at this concept, look what I found on MSDN:
"To use enumerated types when composing VBScript or JScript script files, copy the relevant constant definitions from the relevant"... "file to the constant declarations in your code."
For example, include the following code in the declarations section of your script:
The declaration of constants allows you to write the following:
If you always declare the appropriate constants in your declarations section at the beginning of each script, you can use enumerated types as you use them in C++ programs.
Alternatively, you can achieve the same effect by hard-coding the values, as shown in the following code:
These lines will perform the same task as the previous code lines, without the use of enumerated types.
When composing Windows script (.wsf) files that will run in a Windows Script Host environment, the constants can be included by including a <reference> element. The following code example, which displays the name of each network rule defined for the local computer followed by the value of its RoutingType property, shows how to include the ISA Server administration COM library in a .wsf file:
< Message edited by TNO -- 12/4/2006 8:08:59 PM >
_____________________________
To iterate is human, to recurse divine. -- L. Peter Deutsch
doesn't count "rule.AccessProperties.AppliesToContentMethod = fpcAppliesToAllContent" or "Case fpcRoute" as 'using the enum'? What would you consider a 'real' solution - as opposed to 'work around'?