Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you interpret this Code ?

Status
Not open for further replies.

JohnBates

MIS
Joined
Feb 27, 2000
Messages
1,995
Location
US
Hello everyone - It is obvious to me that the code below can change the value of iSelectedSpur to (2 to the power of isorttype). What I DONT understand is the use of OR


WHICH value gets assigned... is it always the HIGHER value?

Thanks for any help. John


If isorttype <> 0 Then


********* This is the statement I don't understand *******

iSelectedSpur = iSelectedSpur Or 2 ^ isorttype


End If
 
The value assigned to iSelectedSpur is a binary combination of the two values; iSelectedSpur Or'd with the value in isorttype. If either bit in either number is a one (set) then the result of that comparision is a one. If both are zero, the result is a zero. For example if isorttype = 1 and iSelectedSpur value = 9:

Code:
    original iSelectedSpur value = 9   1001
                           2 ^ 1 = 2   0010
                                       ----
  iSelectedSpur Or 2 ^ isorttype = 11  1011

Here's the AND operation where both bits must be set for a resultant 1:
Code:
    original iSelectedSpur value = 9   1001
                           2 ^ 1 = 2   0010
                                       ----
 iSelectedSpur AND 2 ^ isorttype = 0   0000


Mark
 
John &amp; Mark -

Be advised in the next version of VB (VB.NET), &quot;Or&quot; will always do logical comparisons. There will be a new operator called &quot;BitOr&quot; that will do binary operations on whole numbers.

So, if you want to check if either variable contains non-zero values, you'd do:
[tt]
c = a or b
[/tt]
and c will contain a 1 or 0, depending on the boolean logic of a or b being non-zero.

If you want to do a binary OR operation (like Mark did in his excellent example), you'd have to do this:
[tt]
c = a BitOr b
[/tt]

Chip H.
 
Or Round Numbers

Function Round(nValue As Double, nDigits As Integer) As Double
Round = Int(nValue * (10 ^ nDigits) + 0.5) / (10 ^ nDigits)
End Function

Private Sub Form_Load()
'Replace '19.8455' with the number you want to round, replace '2' with the number of
'digits after the point that the rounded numbr will have.
MsgBox Round(19.8455, 2)
End Sub

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top