|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
enumeration helpCan someone explain, or point me to a good link that explains enumerations
for a newbie. Thats 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 > 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 >> AMDRIT wrote:
> enum fileaccess The assignment above does /not/ do what you want:> faReadLock =0 > faWriteLock=1 > faReadShare=2 > faWriteShareRead=4 > faWriteShareWrite = 8 > end enum > > dim pintFileAccess as fileaccess = fileaccess.faWriteShareRead and > fileaccess.faWriteShareWrite > Dim pintFileAccess As fileaccess _ this works out to> = fileaccess.faWriteShareRead And fileaccess.faWriteShareWrite 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. 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 >> > > |
|||||||||||||||||||||||