MS-Access 枚举(特别是 V2007/2010)

问题描述 投票:0回答:1

这个问题是关于 MS-Access 枚举(特别是 2007/2010)。

如何减少具有相同颜色枚举来控制传递给函数的颜色选择的代码行。

Public Enum lngColor1
    Black = 0
    Maroon = 128
    Green = 32768
    Olive = 32896
    Navy = 8388608
    Purple = 8388736
    Teal = 8421376
    Gray = 8421504
    silver = 12632256
    Red = 255
    Lime = 65280
    Yellow = 65535
    Blue = 16711680
    Fuchsia = 16776960
    White = 16777215
End Enum

Public Enum lngColor2
    Black = 0
    Maroon = 128
    Green = 32768
    Olive = 32896
    Navy = 8388608
    Purple = 8388736
    Teal = 8421376
    Gray = 8421504
    silver = 12632256
    Red = 255
    Lime = 65280
    Yellow = 65535
    Blue = 16711680
    Fuchsia = 16776960
    White = 16777215
End Enum

Function WhatEver(ByVal lngXColor1 as lngColor1, ByVal lngXColor2 as lngColor2)
    ' do what ever with the function parameters
End Function

我尝试将颜色定义为自己的枚举,并将枚举放入 lngColor1 和 lngColor2 但 IntelliSense 仅显示颜色枚举的名称,而不显示颜色选择本身。

我实际上有 9 个枚举,具有相同的 15 种颜色选择。

vba ms-access enums
1个回答
0
投票

不确定我完全理解您的要求,但请参阅下文。您可以定义一个

Type
对象来包装枚举,并将其传递给函数。

Public Type ColorType
    Color1 As lngColor1
    Color2 As lngColor2
    '...
End Type

Function WhatEver(ByRef myColorType As ColorType)
    
    Dim x As lngColor1, y As lngColor2
    
    x = myColorType.Color1
    y = myColorType.Color2
    
    Debug.Print x
    Debug.Print y

End Function

最后,调用你的函数。

Sub T()

    Dim ct As ColorType
    
    ct.Color1 = lngColor1.Purple
    ct.Color2 = lngColor2.Fuchsia
    
    Dim r
    r = WhatEver(ct)

    ' 8388736 
    ' 16776960 

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.