locked
Does vbs support enum? RRS feed

  • Question

  • I want to do the following from vbs. Can I use the enum's of the class or do I have to create a set of constants that mimic the enums?
    I hope that vbs does it simply without other tools like Windows Script Host.


    Example

    ' This is the construct of the sample dll
    public class myclass
      public enum tooltype
        porche=0
        ferarri=1
      end enum
      public sub myToolType(byval t as tooltype)
         ' do something with t
      end sub
    end class

    ' I was hoping to use the enum from vbs like this

    -----------------------------------------------
    dim obj
    set obj = createobject("dll.myclass")

    ' set the tool type for the class
    obj.myToolType = obj.tooltype.porche '<-- i have already tried it but in vain. i can't do it.
    -----------------------------------------------
    ' do I have to use constants in vbs to mimic enums?

    Const porche = 0
    Const ferarri = 1

    dim obj
    set obj = createobject("dll.myclass")

    ' set the tool type for the class
    obj.myToolType = porche

     

    Monday, May 9, 2011 5:44 AM

Answers

  • You cannot use enumerated values from the Class because early binding is not supported. Yes, you need to create constants for the enumerated values.


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by macho_daddy Monday, May 9, 2011 9:13 PM
    Monday, May 9, 2011 5:19 PM

All replies

  • This is in no way a VBS forum but a VB Express forum, those are related in an anology as Spanish to English.

    Moderators can this be replaced to Off Topic, it gives only hits in search engines.

     


    Success
    Cor
    Monday, May 9, 2011 8:39 AM
  • You cannot use enumerated values from the Class because early binding is not supported. Yes, you need to create constants for the enumerated values.


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by macho_daddy Monday, May 9, 2011 9:13 PM
    Monday, May 9, 2011 5:19 PM
  • Paul.

    I knew you are an VBS expert but never wants to know that

    :-)

     


    Success
    Cor
    Monday, May 9, 2011 5:44 PM
  • I have no choice Cor. I still have a very large Classic ASP app to maintain. ;-)
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Monday, May 9, 2011 5:50 PM
  • I have no choice Cor. I still have a very large Classic ASP app to maintain. ;-)
    Paul ~~~~ Microsoft MVP (Visual Basic)

    Do you have to go out and hunt for your own food, also? ;)

    It's pretty rough going back to the old VBS from .NET.


    Stephen J Whiteley
    Monday, May 9, 2011 8:36 PM
  • They gave me a spear and sling shot for when it turns dark, but I always notice that one or two of my co-workers are missing the next morning. ;-)
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Tuesday, May 10, 2011 1:18 PM
  • Paul,

    Your answer is very useful for me because I could make my mind of giving up VBscript and go forward.
    Actually I was waving how to do next till I received your answer.

    Thanks,

    macho_daddy

     

    Wednesday, May 11, 2011 3:44 AM