Enum with vbscript

Since vbscript does not support enumerations, is there any work around this problem?

I have this code:

Private Enum dataType dt_Nothing dt_Boolean dt_Decimal dt_Double dt_Integer dt_string dt_Array dt_NetJSON End Enum 

Thanks in advance!

+4
source share
4 answers

According to http://www.tek-tips.com/viewthread.cfm?qid=1146844 the best way is to use constants.

 Const dt_Nothing = Something Const dt_Boolean = Something Const dt_Decimal = Something Const dt_Double = Something Const dt_Integer = Something Const dt_string = Something Const dt_Array = Something Const dt_NetJSON = Something 

I could not find another way. I will search if there is a better way.

+5
source

Using constants is quite logical. Alternatively, you can use a global instance of your own class that mimics VB Enums. Please note that it will look just like an enumeration, and I'm not sure if this is really necessary.

 Class EnumDataType Public dt_Nothing, dt_Boolean, dt_Decimal Private Sub Class_Initialize dt_Nothing = 1 dt_Boolean = 2 dt_Decimal = 4 End Sub End Class Dim dataType Set dataType = New EnumDataType WScript.Echo dataType.dt_Nothing Or dataType.dt_Boolean Or dataType.dt_Decimal 
+5
source

Another way I sometimes use is to declare a dictionary. Like:

Dim oenum

set oEnum = CreateObject ("scripting.Dictionary")

And when initializing the thread / application, I populate it with the values ​​that I like to use, also I have to use an enumeration.

So:

oEnum.Add 0, "Enum1"

oEnum.Add 1, "Enum2"

In a place in the code that I like to use enumeration, I call this dictionaryobject as follows: someval = oEnum.Items () (index) -> an index is kind of like an enumeration method.

Grz John

0
source

Here are the lines of code that I found that worked.

 Const navOpenInNewTab = &H800 Set IE1=CreateObject("InternetExplorer.Application") IE1.Visible=true IE1.Navigate2 "http://blogs.msdn.com" IE1.Navigate2 "http://blogs.msdn.com/tonyschr", CLng(navOpenInNewTab) IE1.Navigate2 "http://blogs.msdn.com/oldnewthing", CLng(navOpenInNewTab) IE1.Navigate2 "http://msdn.microsoft.com", CLng(navOpenInNewTab) 

'Remember to close IE using the following line of code: IE1.Quit

-4
source

All Articles