6

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!

5 Answers 5

9

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
Sign up to request clarification or add additional context in comments.

1 Comment

Nice Solution. worked perfectly
7

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.

Comments

0

Another way I sometimes use is declare an dictionary. Like:

Dim oEnum

set oEnum = CreateObject("scripting.Dictionary")

And on thread/app init I do fill it with the values I like to use likewise I should use the enumeration.

So :

oEnum.Add 0, "Enum1"

oEnum.Add 1, "Enum2"

At the place in code I like to use the enumeration I call this dictionaryobject like: someval = oEnum.Items()(index) -> the index is kinda like the enumeration method.

Edit: you could use this also like:

oEnum.Add "CONSTANTNAME", integer value

Then you can get the value via:

oEnum.Item(CONSTANTNAME)

Grz John

Comments

0

Just to remind, you can avoid bloat and make it painless by doing (eg) this..

Public Const xupv = 1, xvet = 2, xhid = 3, xban = 4, xrep = 5, xech = 6, xvus = 7, xfDpth = 8, xEds = 9

Or this..

Public Const _
  xupv = 1 _
, xvet = 2 _
, xhid = 3 _
, xban = 4 _
, xrep = 5 _
, xech = 6 _
, xvus = 7 _
, xfDpth = 8 _
, xEds = 9

(That's tested. parses fine)

Comments

-5

Here are 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)

'Don't forget to close IE using the line of code below: IE1.Quit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.