Is there a way to get the enums in VBA?

前端 未结 8 1870
南旧
南旧 2020-12-06 07:51

Is there a way to get the enums in VBA? Something like this example for C#, but for VBA?

using System;

class EnumsExampleZ
{
    private enum SiteNames
             


        
8条回答
  •  有刺的猬
    2020-12-06 08:30

    For above "John Coleman"'s example I suggest to use next functions:

    Function FruitType2Int(Fruit As FruitType)
        FruitType2Int = Format("0", Fruit)
        Debug.Print FruitType2Int
    End Function
    
    Function int2FruitString(i As Integer) As String
        If i = FruitType2Int(Orange) Then
            int2FruitString = "Orange"
        ElseIf i = FruitType2Int(Plum) Then
            int2FruitString = "Plum"
        ElseIf i = FruitType2Int(Apple) Then
            int2FruitString = "Apple"
        Else
            int2FruitString = "?"
        End If
        Debug.Print int2FruitString
    End Function
    

    Direct use of an Array indexes (without LBound() and etc.) may cause different resuts, depends on value in Option Base 1

提交回复
热议问题