Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum with vbscript

Tags:

enums

vbscript

Since vbscript does not support enumerations, is there any work arround to face 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!

like image 434
matt Avatar asked Jun 21 '12 13:06

matt


People also ask

What is enum in vbscript?

In VB.NET, Enum is a keyword known as Enumeration. Enumeration is a user-defined data type used to define a related set of constants as a list using the keyword enum statement. It can be used with module, structure, class, and procedure.

How do I create an enum in Visual Studio?

After all, enum is also a type! And often you would want to create one file for one enum definition. For doing so, you have to create a blank code file and add the namespace definition in it. After that, you have to insert the enum snippet in the file.

What is enum statement?

Defines a user-defined enumeration (also known as an enumerated type or enum). An enum is made up of a list of strongly typed, named constants called members. The value of a variable defined as an enum is restricted to the list of members defined for that enum.

What is enum in Visual Studio?

An enumeration type (or enum type) is a value type defined by a set of named constants of the underlying integral numeric type. To define an enumeration type, use the enum keyword and specify the names of enum members: C# Copy.


2 Answers

Using constants is quite logical. On the other hand you can use a global instance of your own class that mimics VB Enums. Note that, will look just like enums and I'm not sure it 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
like image 72
Kul-Tigin Avatar answered Sep 27 '22 21:09

Kul-Tigin


According to http://www.tek-tips.com/viewthread.cfm?qid=1146844 the best way is by using 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 couldn't find another way. I will search if there is a better way.

like image 34
matt Avatar answered Sep 27 '22 21:09

matt