[AccessD] OT: Programming Logic

Heenan, Lambert Lambert.Heenan at AIG.com
Fri Feb 14 15:07:01 CST 2003


It's all done with a little AND/OR logic. Simplest way is to define some
constants first.

Const FirstBit = 1
Const SecondBit = 2
Const ThirdBit = 4
Const FifthBit = 8

etc. Of course the names would be more meaningful in a real application.

So to SET the bits you want you combine the constants (in exactly the same
way as you can combine the button and icon constants for the MsgBox
function)

Dim nMyBits as Long

	nMyBits = FirstBit OR ThirdBit
	... 
	' code that stores nMyBits in a numeric field in a table
	...

Then to find out if a given bit has been set you just reverse the process
using AND
	...
	' code to retrieve the bit field from the table and put it in a
variable
	' called "nTheBits" - A LongInt
	If nTheBits AND FirstBit <> 0 Then
		' bit One is set, do something appropriate
	End If

HTH

Lambert


> -----Original Message-----
> From:	Joe Rojas [SMTP:JRojas at tnco-inc.com]
> Sent:	Friday, February 14, 2003 3:27 PM
> To:	'accessd at databaseadvisors.com'
> Subject:	[AccessD] OT: Programming Logic
> 
> Hi All,
> 
> 	I have seen in a couple of programs that use flags to set options
> that work by giving a "binary" value, if you will, to each setting. For
> example, the first setting has the value 1, the second 2, then 4,
> 8,16,32,64,etc. Then it will add up the values of the settings that have
> been turned on. So if the 3rd, 5th, and 7th settings were turned on the
> value would be 84 (4+16+64). The totaled value generated would be unique,
> i.e. no two combinations of settings would produce the same totaled value.
> 
> 	Here is the part that I get stumped on...how would one program a
> function that would take a totaled value and "break it up" into the
> individual values that made it up? For example, if given the value 84, it
> would "break it up" as 4, 16, and 64.
> 
> Any ideas would be appreciated.
> 
> Thanks,
> Joe Rojas
> 
> 
> 
> 
> 
> This electronic transmission is strictly confidential to TNCO, Inc. and
> intended solely for the addressee. It may contain information which is
> covered by legal, professional, or other privileges. If you are not the
> intended addressee, or someone authorized by the intended addressee to
> receive transmissions on behalf of the addressee, you must not retain,
> disclose in any form, copy, or take any action in reliance on this
> transmission. If you have received this transmission in error, please
> notify
> the sender as soon as possible and destroy this message. While TNCO, Inc.
> uses virus protection, the recipient should check this email and any
> attachments for the presence of viruses. TNCO, Inc. accepts no liability
> for
> any damage caused by any virus transmitted by this email.
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com



More information about the AccessD mailing list