Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Colors 24 Bits and Binary Conversion

Introduction.

If you have been following the last four articles on Number Systems (Decimal, Binary, Octal, and Hexadecimal), here’s something interesting for you to explore. Before we dive in, I recommend reviewing those earlier articles using the links provided below. Doing so, you know the background information on this topic, understand the concept more clearly, appreciate its practical usefulness, and enjoy experimenting with the methods we are about to discuss.

  1. Learn the Binary Numbering System
  2. Learn Binary Numbering System-2
  3. Octal Numbering System
  4. Hexadecimal Numbering System


Color Number Range 0 to 16 Million.

The image above shows an MS-Access Form where you can enter a Decimal Number ranging from 0 to 16,777,215 (the maximum value represented by a 24-bit binary number). The form converts the entered value into its Binary equivalent and simultaneously uses the number to generate an RGB color, displayed in the top color band. With this method, you can visualize over 16 million possible colors on the form.

In the example shown, the value 65535 is entered in the text box. The corresponding Binary representation (1111111111111111) is displayed in the gray band just above the text box. Each binary digit is aligned under a label in red font, which represents the decimal value of that bit position. By adding together all these red-labeled values where the binary digit is You arrive at the decimal number entered in the text box.

The Red, Green, and Blue (RGB) Colors.

Bits 0 to 7 (the first 8 bits) represent the Red component, while bits 8 to 15 (the next 8 bits) represent the Green component. When both Red and Green are at full strength, they combine to produce Yellow, which is displayed on the top color band above the Red, Green, and Blue bars.

Now, let’s slightly modify this sample color. Starting with the value 65535, click on the labels with the values 4096 and 64. Each selected value is transferred into the text box and subtracted from 65535. The clicked labels return to their default black font color, indicating that those bit values are no longer active.

Finally, click the Convert command button. The updated result (the new RGB number) is displayed in blue beneath the text box, and the top color band updates to show the new color generated after subtracting the selected bit values. See the image below for reference.

If you would like to add more Red, Green, or Blue to the existing color number, simply click on the labels that display numbers in black font. Each selected value will be added to the current color, and when you click the Convert command button, the new result will be displayed in the top color band. The intensity of the added color depends on the magnitude of the number chosen within the respective color band. Once a value is included, its label font changes to red, indicating that it has been added to the current color number.

If you click a label that is already red, its font will switch back to black, meaning that value will now be subtracted from the total. Again, click the Convert command button to evaluate the final color value. The updated binary digits of the selected values will appear in the gray band above the text box each time, allowing you to trace which bits are active.

To restore the form to its default state, click the Reset command button.

How to make a Color Choice?

You can use one of the three methods given below or a mix of all three to enter the number into the TextBox:

  1. Enter a Decimal Number directly into the TextBox and click the Convert command button.

  2. Enter a valid expression into the TextBox (for example: 2^10 + 2^5 + 5*25 + 1638) and click the Convert command button. The expression will be evaluated, and the result will be converted.

  3. Click on the labels beneath the Red, Green, and Blue color bands to select values and combine them into a new color. Each clicked value is added to the TextBox as part of an expression, and its label font changes to red, showing it has been included. Clicking the same label again will subtract that value, and the font will revert to black color. When ready, click the Convert command button to apply the result.

  4. You can also combine all three methods—direct number entry, expressions, and label selections—to arrive at a valid color number between 1 and 16,777,215 (16777215 = 256 Blue × 256 Green × 256 Red – 1).

Get the result in three ways:

  1. The RGB Color equal to the number selected is displayed on the top color band.
  2. The Binary Number.
  3. The RGB Color Number of the top color band.

How to Use the Newly Created Color.

You can use this color number when designing Forms or Controls in Access by setting it as the Background, Foreground, or Border Color in the Property Sheet of the Form or Control. If you are a web designer, you can convert the decimal color number into a hexadecimal value and use it in your style sheets. To do this, call the function Hex(DecimalNumber) in the Debug Window. The result will give you the 24-bit hexadecimal format, which can be applied directly in CSS, for example: #0000FF for the decimal color value 255.

Enter the number 16777215 in the Text Box and click the Convert Command Button to change the top color band to white.

You can download a database with the above Form and Programs by clicking on the Download link below:

Technorati Tags:

Download Demo Database

Download Demo Binary.zip


Share:

No comments:

Post a Comment

Comments subject to moderation before publishing.

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code