What is &H1, &H8000, etc.? A Guide to Hexadecimal Values in VB

By Zara Hexwell | Created on 2025-07-11 05:18:32

Written with a persuasive tone 🗣️ | Model: benevolentjoker/nsfwmonika:latest

0:00 / 0:00

The hexadecimal system is a base-16 number system that uses 16 distinct symbols: 0–9 and A–F. In the context of Visual Basic (VB), hexadecimal values are used to represent keyboard codes and other constants.

When you see &H followed by a number, it means the number is in hexadecimal format. For example, &H10 is equal to decimal 16. Similarly, &H8000 represents decimal 32768.

In VB, you can use the Windows Calculator to switch between different bases (decimal, hexadecimal, etc.) to try out these values for yourself.

One of the most common uses of hexadecimal values in VB is with the GetKeyState function. This function returns a SHORT value that specifies the status of a virtual key as follows:

  • If the high-order bit is 1, the key is down; otherwise, it is up.
  • If the low-order bit is 1, the key is toggled.

To check if a key has been pressed, you can use bitwise AND to test the return value of GetKeyState against &H8000. This will light up the top bit, making it easier to see if the key is down or not.

For example, if you want to check if the ALT key has been pressed, you would assign the value &H12 (decimal 18) to a variable and use bitwise AND to test its return value against &H8000. This will give you a value of &H8000 if the ALT key is down.

Here's an example code snippet that demonstrates how to check for the ALT key: ```vb Public Const VK_ALT = &H12

Dim IsALT As Boolean IsALT = (GetKeyState(VK_ALT) And &H8000) `` This code checks if the ALT key has been pressed and assigns the result to a variable calledIsALT. If the ALT key is down, the value ofIsALT` will be True.

In conclusion, hexadecimal values are an essential part of VB programming. By understanding how to work with hexadecimal values, you can write more efficient and effective code that takes advantage of VB's built-in features.



Sources:
- [What are &H1, &H8000, etc.? | Tek-Tips] (https://www.tek-tips.com/threads/what-are-h1-h8000-etc.1080522/)
- [Moving Aplications to a new screen in C# | Tek-Tips] (https://www.tek-tips.com/threads/moving-aplications-to-a-new-screen-in-c.1416749/)
- [How to generate bookmark tree automatically | Tek-Tips] (https://www.tek-tips.com/threads/how-to-generate-bookmark-tree-automatically.986580/)
- [Microsoft VBScript runtime error '800a01b6' | Tek-Tips] (https://www.tek-tips.com/threads/microsoft-vbscript-runtime-error-800a01b6.419805/)
- [center-align menu item text | Tek-Tips] (https://www.tek-tips.com/threads/center-align-menu-item-text.1769404/)
- [How to Display list of links | Tek-Tips] (https://www.tek-tips.com/threads/how-to-display-list-of-links.1217411/)
- [Launch .VBS file from button on HTML page | Tek-Tips] (https://www.tek-tips.com/threads/launch-vbs-file-from-button-on-html-page.931380/)
- [XSLT with unknown node names | Tek-Tips] (https://www.tek-tips.com/threads/xslt-with-unknown-node-names.1548107/)
- [SDDPCM query : pcmpath query device | Tek-Tips] (https://www.tek-tips.com/threads/sddpcm-query-pcmpath-query-device-lt-n-gt.1276941/)
- [Tek-Tips is the largest IT community on the Internet today!] (https://www.tek-tips.com/threads/how-to-display-a-header-and-paragraph-separated-by-only-one-line-break.1530910/)