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!
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.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With