Click here to Skip to main content
15,896,557 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionBitwise AND in an If/Else block Pin
treddie7-May-13 11:33
treddie7-May-13 11:33 
AnswerRe: Bitwise AND in an If/Else block Pin
Dave Kreskowiak7-May-13 14:49
mveDave Kreskowiak7-May-13 14:49 
GeneralRe: Bitwise AND in an If/Else block Pin
treddie7-May-13 17:04
treddie7-May-13 17:04 
GeneralRe: Bitwise AND in an If/Else block Pin
Richard MacCutchan7-May-13 21:19
mveRichard MacCutchan7-May-13 21:19 
GeneralRe: Bitwise AND in an If/Else block Pin
treddie7-May-13 22:38
treddie7-May-13 22:38 
GeneralRe: Bitwise AND in an If/Else block Pin
Bernhard Hiller7-May-13 23:07
Bernhard Hiller7-May-13 23:07 
GeneralRe: Bitwise AND in an If/Else block Pin
Dave Kreskowiak8-May-13 1:58
mveDave Kreskowiak8-May-13 1:58 
GeneralRe: Bitwise AND in an If/Else block Pin
treddie8-May-13 11:23
treddie8-May-13 11:23 
The Not operator will invert that to False.

But that is not what happens. Here are some actual tests I performed:

The value and the mask in these examples are:
	FileAttributes	Value that contains a bit field that indicates whether a resource is a folder or a file.
			Folder = 8208D, File = 8224D

	Mask		Bit mask that tests for the presence of a folder (16D).

Option Strict is NOT set.
_____________________________________________________________________________________________________

GOAL:  Run code on "True" condition (Resource is a folder):
	If (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
		 'Execute code.
	End If

	When FileAttributes = 8208D (Folder):
		8208D (Folder)    =    		2	0	1	0	H
						0010	0000	0001	0000	B
		16D (Mask)        =	AND	0000	0000	0001	0000	B
                                                _________________________________
		Result			        0000	0000	0001	0000	B    <>	0, ("True"), Code executes as it should.


	When FileAttributes = 8224D (File):
		8224D (File)    =    		2	0	2	0	H
						0010	0000	0010	0000	B
		16D (Mask)      =	AND	0000	0000	0001	0000	B
                                                _________________________________
		Result			        0000	0000	0000	0000	B     =	0, ("False"), Code does not execute.
												      This is correct.
_____________________________________________________________________________________________________

GOAL:  Run code on "False" condition (Resource is a file):
	If Not (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
		 'Execute code.
	End If

	When FileAttributes = 8208D (Folder):
		8208D (Folder)    =    		2	0	1	0	H
						0010	0000	0001	0000	B
		16D (Mask)        =	AND	0000	0000	0001	0000	B
                                                _________________________________
		Result			        0000	0000	0001	0000	B    <> 0, ("True"), Code WOULD  execute, if left as is.
                                                _________________________________
					NOT	1111	1111	1110	1111	B    <>	0, ("True"), Code executes when it SHOULD NOT.


	When FileAttributes = 8224D (File):
		8224D (File)    =    		2	0	2	0	H
						0010	0000	0010	0000	B
		16D (Mask)      =	AND	0000	0000	0001	0000	B
                                                _________________________________
		Result			        0000	0000	0000	0000	B    =  0, ("False"), Code does not execute, if left as is.
                                                _________________________________
					NOT	1111	1111	1110	1111	B    <>	0, ("True"), Code executes as it should.
________________________________________________________________________________________________________________________________________________________________


I can only conclude from all of this, that an If condition without an equality can only execute code on "True", and never on "False".
GeneralRe: Bitwise AND in an If/Else block Pin
Dave Kreskowiak8-May-13 13:18
mveDave Kreskowiak8-May-13 13:18 
GeneralRe: Bitwise AND in an If/Else block Pin
Richard MacCutchan8-May-13 20:56
mveRichard MacCutchan8-May-13 20:56 
GeneralRe: Bitwise AND in an If/Else block Pin
treddie8-May-13 22:14
treddie8-May-13 22:14 
AnswerRe: Bitwise AND in an If/Else block Pin
Richard MacCutchan9-May-13 1:07
mveRichard MacCutchan9-May-13 1:07 
GeneralRe: Bitwise AND in an If/Else block Pin
treddie10-May-13 16:14
treddie10-May-13 16:14 
GeneralRe: Bitwise AND in an If/Else block Pin
Richard MacCutchan8-May-13 2:53
mveRichard MacCutchan8-May-13 2:53 
AnswerRe: Bitwise AND in an If/Else block Pin
TnTinMn8-May-13 3:24
TnTinMn8-May-13 3:24 
GeneralRe: Bitwise AND in an If/Else block Pin
treddie8-May-13 22:15
treddie8-May-13 22:15 
Questioncascading comboboxes vb.net windows forms Pin
Agontuk6-May-13 8:39
Agontuk6-May-13 8:39 
AnswerRe: cascading comboboxes vb.net windows forms Pin
NotPolitcallyCorrect6-May-13 10:15
NotPolitcallyCorrect6-May-13 10:15 
GeneralRe: cascading comboboxes vb.net windows forms Pin
Agontuk7-May-13 0:42
Agontuk7-May-13 0:42 
AnswerRe: cascading comboboxes vb.net windows forms Pin
Simon_Whale7-May-13 1:30
Simon_Whale7-May-13 1:30 
AnswerRe: cascading comboboxes vb.net windows forms Pin
Dave Kreskowiak7-May-13 1:44
mveDave Kreskowiak7-May-13 1:44 
GeneralRe: cascading comboboxes vb.net windows forms Pin
Agontuk9-May-13 8:53
Agontuk9-May-13 8:53 
QuestionHow to export the data from datagridview & all the data on the form1.vb make a report Pin
chandan H T5-May-13 1:24
chandan H T5-May-13 1:24 
AnswerRe: How to export the data from datagridview & all the data on the form1.vb make a report Pin
Eddy Vluggen5-May-13 8:49
professionalEddy Vluggen5-May-13 8:49 
QuestionTreeView Find not working Pin
treddie4-May-13 22:17
treddie4-May-13 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.