Wrox Programmer Forums
BOOK: Visual Basic 2010 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2010 Programmer's Reference by Rod Stephens; ISBN: 9780470499832
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2010 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 31st, 2011, 10:30 PM
Authorized User
Join Date: May 2011
Posts: 46
Thanks: 27
Thanked 0 Times in 0 Posts
Default Ch. 9 Anchor

Your book code anchors the button at 'bottom OR right'. I expected these results using 'AND'. When I tried 'AND' the results were unexpected. Is using 'OR' here just an idiosyncrasy to be aware of or is there some reason why 'OR' works the way I would expect 'AND' to work?

Keith Z.
Old November 1st, 2011, 11:16 AM
Rod Stephens's Avatar
Wrox Author
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts

Sorry that does seem confusing. The issue is the difference between logical And/Or and bitwise And/Or.

The Anchor property (and some other properties) are bit masks. If you were to look at their values as binary numbers, you would see specific bits were to 0 to indicate a value is not set and 1 to indicate that a bit is set. So when you set Anchor = Left, for example, that sets the bit for Left.

To set more than one bit, you use Or to combine the values. For example, setting Anchor = Bottom or Right means to set the binary value so a bit is set if the corresponding bit in either the Bottom or Right value is set. If Bottom is 00001000 and Right is 00000010 (they aren't--this is just an example) then the result would be 00001010.

So the way you make the logical statement "anchored to the bottom and right" to be true is you use the bitwise Or operator to set both of the bits in the Anchor property.

Let me know if that's unclear and I'll try to explain it from a different angle.

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
zavodney (November 1st, 2011)
Old November 1st, 2011, 02:05 PM
Authorized User
Join Date: May 2011
Posts: 46
Thanks: 27
Thanked 0 Times in 0 Posts

Thank you. I understand bit masks. I guess that's 1 more thing to be aware of. If it doesn't work 1 way I guess I will try the other way and then look for a help page if it doesn't work. Looking at the code again I see why it is working the way it does when I used AND. Thanks again.

Keith Z.

Similar Threads
Thread Thread Starter Forum Replies Last Post
image as anchor handoyo BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 4 October 9th, 2009 11:03 AM
Anchor Tag kapilmirchi ASP.NET 1.0 and 1.1 Basics 2 November 18th, 2008 05:57 AM
onClick and go to anchor #something Parabolart Javascript 7 November 28th, 2006 06:45 AM
anchor and get variables. SignalFade Beginning PHP 4 January 19th, 2006 08:56 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.