Is there a way to count elements in a VBA enum?

后端 未结 5 1998
无人及你
无人及你 2021-02-09 14:29

is there a proper way to count elements of an enum in VBA ? At the moment, I leave an enum value such as KeepThisOneHere in the following example

En         


        
5条回答
  •  执念已碎
    2021-02-09 14:48

    Here's an example of my workaround, which is pretty straightforward:

    Enum FileSpecFields
        FileSpecFields_Start                    '(zero-based)
            FileNameIdx = FileSpecFields_Start
            FolderNameIdx
            BasePathIdx
            FullPathIdx
            CopyStatus
        FileSpecFields_End = CopyStatus
    End Enum
    
    '...
    
    ReDim FileSpecList(1 To MaxFiles, FileSpecFields_Start To FileSpecFields_End) As String
    
    '...
    

    But note that, if you are using a one-based Enum you may have to adjust the _End value definition, depending on how you're using it. Also, for zero-based Enums, the _End value is not the same as its count of items. And, if you add items at the end, you must update the _End value's definition accordingly. Finally, if your enum is a non-contiguous range of values, all bets are off with this approach!

提交回复
热议问题