Mouhgouda Mouhgouda - 6 months ago 15
Vb.net Question

Constant with multiple values?

I've stumbled upon that particular bit of code and i'm a bit stumped as the usefulness of it.

Public Const FILE_SHARE_READ as Integer = 1
Public Const FILE_SHARE_WRITE as Integer = 2
Public Const FILE_SHARE_DELETE as Integer = 4
Public Const FILE_SHARE_ALL as Integer = FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE


i tested it a bit and haven't gotten any more insight than :

FILE_SHARE_ALL is always equal to 4 anyways.

Is there something i'm missing?

EDIT: Thanks for your help, i've found out the problem -> Code 18
Copy-paste mistake in my tester the line was

Public Const FILE_SHARE_ALL as Integer = FILE_SHARE_DELETE or FILE_SHARE_DELETE or FILE_SHARE_DELETE


Don't judge me!

Answer
Public Const FILE_SHARE_READ as Integer = 1  
Public Const FILE_SHARE_WRITE as Integer = 2  
Public Const FILE_SHARE_DELETE as Integer = 4  
Public Const FILE_SHARE_ALL as Integer = FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE 

The Or here is a Bitwise or, meaning that the FILE_SHARE_ALL should result with 7, since:

int 1 ' = binary 001
int 2 ' = binary 010
int 4 ' = binary 100  

001 | 010 | 100 = 111 ' equals int 7.
Comments