Thread Tools Rate Thread

# logical and in vb ?

Sam
Guest
Posts: n/a

 20th Apr 2005
Hi,
I'm trying to do the following :

If I have a value of 7 then I want to test if all the values from 0 to
4 can be contained in 7:
2^0 = 1 < 7 so can be contained in 7
2^4 = 16 > 7 so can't be contained in 7

I should do something like 7&0 < 0 ? but I don't know the vb
syntax....
Can someone help?
thx

Sam

Stephany Young
Guest
Posts: n/a

 20th Apr 2005
If (x And 7) = x ' x can be contained in 7

If (x And 7) <> x ' x cannot be contained in 7

"Sam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I'm trying to do the following :
>
> If I have a value of 7 then I want to test if all the values from 0 to
> 4 can be contained in 7:
> 2^0 = 1 < 7 so can be contained in 7
> 2^4 = 16 > 7 so can't be contained in 7
>
> I should do something like 7&0 < 0 ? but I don't know the vb
> syntax....
> Can someone help?
> thx
>
> Sam
>

Sam
Guest
Posts: n/a

 20th Apr 2005
thx

Sam
Guest
Posts: n/a

 20th Apr 2005
humm actually i'm not sure it's what i want.
it returns x all the time as long as x is < 7. But 6 (for example)
cannot be contained in 7 : 2^6 = 64 > 7

Am I wrong ?

Stephany Young
Guest
Posts: n/a

 20th Apr 2005
If you are talking about using a value as a 'field' to hold 'flags' e.g.:

0
1
2
4
8
16
32
64
etc.

Then it will still work. You need to think about the bits.

111 = 7 = 4 Or 2 Or 1
110 = 6 = 4 Or 2
101 = 5 = 4 Or 1
100 = 4 = 4
011 = 3 = 2 Or 1
010 = 2 = 2
001 = 1 = 1
000 = 0 = 0

So, given:

v = 7
a = 0
b = 1
c = 2
d = 4

Then:

v = a Or b Or c Or d

If (v And a) = a Then
Debug.Print "v contains a"
Else
Debug.Print "v does not contain a"
End If

If (v And b) = b Then
Debug.Print "v contains b"
Else
Debug.Print "v does not contain b"
End If

If (v And c) = c Then
Debug.Print "v contains c"
Else
Debug.Print "v does not contain c"
End If

If (v And d) = d Then
Debug.Print "v contains d"
Else
Debug.Print "v does not contain d"
End If

"Sam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> humm actually i'm not sure it's what i want.
> it returns x all the time as long as x is < 7. But 6 (for example)
> cannot be contained in 7 : 2^6 = 64 > 7
>
> Am I wrong ?
>

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Jonathan Microsoft C# .NET 10 6th May 2006 12:19 AM =?Utf-8?B?MmRvZ3M=?= Windows XP General 6 4th Oct 2005 12:19 PM =?Utf-8?B?MmRvZ3M=?= Windows XP Basics 6 3rd Oct 2005 11:35 PM =?Utf-8?B?MmRvZ3M=?= Windows XP New Users 3 3rd Oct 2005 11:10 PM =?Utf-8?B?MmRvZ3M=?= Windows XP Setup 5 3rd Oct 2005 06:30 PM

Features

Advertising

Newsgroups

All times are GMT +1. The time now is 02:10 AM.