Home All Groups Group Topic Archive Search About
Author
8 Jun 2006 2:41 PM
Jason
Can someone explain, or point me to a good link that explains enumerations
for a newbie.

Thats

Author
8 Jun 2006 2:59 PM
AMDRIT
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.

enum fileaccess
  faReadLock =0
  faWriteLock=1
  faReadShare=2
  faWriteShareRead=4
  faWriteShareWrite = 8
end enum

dim pintFileAccess as  fileaccess = fileaccess.faWriteShareRead and
fileaccess.faWriteShareWrite

when you look at the properties of a control in the designer, many times you
will notice use of enumerations.  Windows.WindowsState is an enumeration

FormWindowState.Normal = 0,
FormWindowState.Minimized = 1 ,
FormWindowState.Maximized = 2

Enumerations reduce ambiguity

Show quoteHide quote
"Jason" <some***@microsoft.com> wrote in message
news:%23alVgmwiGHA.1272@TK2MSFTNGP03.phx.gbl...
> Can someone explain, or point me to a good link that explains enumerations
> for a newbie.
>
> Thats
>
Author
8 Jun 2006 9:51 PM
GhostInAK
Hello AMDRIT,

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

-Boo

Show quoteHide quote
> 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.
>
> enum fileaccess
> faReadLock =0
> faWriteLock=1
> faReadShare=2
> faWriteShareRead=4
> faWriteShareWrite = 8
> end enum
> dim pintFileAccess as  fileaccess = fileaccess.faWriteShareRead and
> fileaccess.faWriteShareWrite
>
> when you look at the properties of a control in the designer, many
> times you will notice use of enumerations.  Windows.WindowsState is an
> enumeration
>
> FormWindowState.Normal = 0,
> FormWindowState.Minimized = 1 ,
> FormWindowState.Maximized = 2
> Enumerations reduce ambiguity
>
> "Jason" <some***@microsoft.com> wrote in message
> news:%23alVgmwiGHA.1272@TK2MSFTNGP03.phx.gbl...
>
>> Can someone explain, or point me to a good link that explains
>> enumerations for a newbie.
>>
>> Thats
>>
Author
9 Jun 2006 11:28 AM
Phill W.
AMDRIT wrote:

> enum fileaccess
>   faReadLock =0
>   faWriteLock=1
>   faReadShare=2
>   faWriteShareRead=4
>   faWriteShareWrite = 8
> end enum
>
> dim pintFileAccess as  fileaccess = fileaccess.faWriteShareRead and
> fileaccess.faWriteShareWrite

The assignment above does /not/ do what you want:

> Dim pintFileAccess As fileaccess _
>    = fileaccess.faWriteShareRead And fileaccess.faWriteShareWrite

this works out to

pintFileAccess = 2 And 8
                = 0 !!

I think you meant to say

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"

Note the inherent portability of the latter.

HTH,
    Phill  W.
Author
9 Jun 2006 1:23 PM
AMDRIT
Thank you GhostInAk and Phil W. for pointing out my error.  Despite that, I
hope the explaination answers Jason's question.



Show quoteHide quote
"AMDRIT" <amd***@hotmail.com> wrote in message
news:ONbMNwwiGHA.4276@TK2MSFTNGP03.phx.gbl...
>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.
>
> enum fileaccess
>  faReadLock =0
>  faWriteLock=1
>  faReadShare=2
>  faWriteShareRead=4
>  faWriteShareWrite = 8
> end enum
>
> dim pintFileAccess as  fileaccess = fileaccess.faWriteShareRead and
> fileaccess.faWriteShareWrite
>
> when you look at the properties of a control in the designer, many times
> you will notice use of enumerations.  Windows.WindowsState is an
> enumeration
>
> FormWindowState.Normal = 0,
> FormWindowState.Minimized = 1 ,
> FormWindowState.Maximized = 2
>
> Enumerations reduce ambiguity
>
> "Jason" <some***@microsoft.com> wrote in message
> news:%23alVgmwiGHA.1272@TK2MSFTNGP03.phx.gbl...
>> Can someone explain, or point me to a good link that explains
>> enumerations for a newbie.
>>
>> Thats
>>
>
>