Question : Excel VBA Enum and String

In my macro I use a Function to declare an array from both a UserForm and a Procedure.

The UserForm provides a string that matches the Enum i have created.
But thats the problem.

Can a String be changed to an Enum?

Attached is Snippets of the Code.
NOTE: That is not the complete code.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
'Enum
Enum Location
  Belmont = 0
  Kilkenny = 1
End Enum

'Called from Procedure
LocalArray = ArrayDeclaration(Cont1.Caption)

'Called from UserForm
arrBelmont = ArrayDeclaration(Belmont)
arrKilkenny = ArrayDeclaration(Kilkenny)

'Function
Function ArrayDeclaration(Branch As Location)
Select Case Branch
Case Belmont
ArrayDeclaration = Array("100 - Customer Support", _
                        "101 - Customer Support 101", _
                        "102 - Resellers", _
                        "103 - Company Group Accts", _
                        "104 - Staff Acct", _
                        "121 - Rep 121", _
                        "122 - Rep 122", _
                        "123 - Rep 123", _
                        "124 - Rep 124", _
                        "125 - ASA National Accts", _
                        "126 - Print", _
                        "127 - New Business", _
                        "128 - Rep 128", _
                        "132 - Rep 132", _
                        "141 - Furniture", _
                        "151 - Rep 151")
Case Kilkenny
ArrayDeclaration = Array("201 - Customer Support SA", _
                        "221 - David Surname", _
                        "222 - Tracey Surname", _
                        "224 - Myrtle Surname", _
                        "225 - ASA Accounts SA", _
                        "226 - Brenton Surname")
End Select
End Function

Answer : Excel VBA Enum and String

If you are going to keep adding check boxes then you could use a simple converter function:

Public Function LocationEnum(ByVal Location As String) As Long
    Select Case Location
        Case "BELMONT": LocationEnum = 0
        Case "KILKENNY": LocationEnum = 1
    End Select
End Function

This is sort of along the lines that Tom was suggesting but without creating an actual class.

Use it like so:

   EnumValue = LocationEnum(CheckBox1.Caption)

Kevin
Random Solutions  
 
programming4us programming4us