-
Data Types
:confused:
Is there a way to define a custom data type that only allows certain values?
For instance, I would like to create a datatype of SIZE which could hold values of SMALL, MEDIUM, LARGE exclusively. I figure I could do this through making constants for each that translate to 1, 2, and 3 and then doing SIZE as a byte, but I would prefer the more streamlined method.
Thank you.
-
:)
Upon clicking back over to the VB Help file I noticed that under constants, the topic I had been searching, a heading for 'enumeration', which rang a bell, and thus my question is answered.
Private Enum Size
Small
Medium
Large
End Enum
-
I think you are talking about enumeration:
The following code goes in the general declarations section of a form or module
Code:
Enum enmMySizes
SMALL = 0
MEDIUM = 1
LARGE = 2
End Enum
Then assign it to a variable to use it:
Code:
Dim Sizes as enmMySizes
If Sizes = MEDIUM Then
'Do Something
End If