I always think of enumerations as a logical grouping of numerical constants.
A bonus of enumerations is that you can assign multiple values to a single
variable.
The code you propose below will give pintFileAccess a value of faReadLock
(0). I believe you were trying to give it a value that would express both
the faWriteShareRead and faWriteShareWrite values (12). You would produce
this value by using a bitwise OR instead of an AND.
Dim pintFileAccess As FileAccess = FileAccess.faWriteShareRead OR FileAccess.faWriteShareWrite
Dim pintFileAccess as fileaccess _
= fileaccess.faWriteShareRead Or fileaccess.faWriteShareWrite
Also, if you're going to do this sort of "bit-wise" combination, you
should add the Flags() attribute to your Enumeration.
Contrast ...
Enum FileAccess
.. . .
Dim a As FileAccess _
= FileAccess.faWriteShareRead Or FileAccess.faReadShare
? a.ToString()
12
.... with ...
<Flags()> Enum FileAccess
.. . .
Dim a As FileAccess _
= FileAccess.faWriteShareRead Or FileAccess.faReadShare
? a.ToString()
"faWriteShareRead, faWriteShareWrite"
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.