A Guide to Understanding Hexadecimal Values in Visual Basic

By Zachary P. Byteston | Created on 2025-08-28 15:07:06

Written with a informative tone 📝 | Model: keyless-claude-3-haiku

0:00 / 0:00
As a developer, understanding hexadecimal values is crucial for working with keyboard input functions in Visual Basic. In this guide, we'll explore what &H1, &H8000, and other similar values mean. Hexadecimal notation uses the digits 0-9 and letters A-F to represent numbers. It's often used in programming to represent binary data, such as keyboard keys or mouse button states.

What is Hexadecimal Notation?

In hexadecimal notation, each digit represents a power of 16. The rightmost digit represents the units place (16^0), and the next digit to the left represents the 16's place (16^1), and so on. For example, the hexadecimal value &H10 would be represented in binary as: 00000000 00000001 In this representation, the first digit (&H) indicates that the following digits are in hexadecimal notation. The number 0 is used to pad the left side of the binary number to make it a multiple of four bits.

How Does It Relate to Keyboard Input Functions?

When working with keyboard input functions, such as GetKeyState or HookStruct, you'll often see values like &H10, &H12, and &H8000. These values represent the virtual key codes for specific keys on the keyboard. For example, the value &H10 represents the VK_SHIFT key code, while &H12 represents the VK_ALT key code. When using these values in a conditional statement, you'll need to use bitwise AND to check whether the corresponding key is pressed or not.

Example Usage

Here's an example of how you might use hexadecimal values in a function that copies text from an input box to the clipboard when the user selects ALT and X: Public Const VK_ALT = &H12 Public Type KBDLLHOOKSTRUCT vkCode As Long ' virtual keycode scanCode As Long ' hardware scancode flags As Long time As Long dwExtraInfo As Long End Type Dim IsALT As Boolean IsALT = (GetKeyState(VK_ALT) And &H8000) 'Ctrl Key tempVKCodeHolder = correctedInputValues(CInt(Trim(HookStruct.vkCode))) 'Takes the interpreted keyboard input value and translates it to it's proper ascii value. If ((IsAlt = True) And (tempVKCodeHolder = 88)) Then 'If ALT and "X" are pressed at the same time, 'the user's data Copied to the Clipboard. Clipboard.Clear Clipboard.SetText (strUserInput) Exit Function End If In this example, we're using the hexadecimal value &H12 to represent the VK_ALT key code. We're then using bitwise AND with &H8000 to check whether the ALT key is pressed or not.

Conclusion

In conclusion, understanding hexadecimal values is crucial for working with keyboard input functions in Visual Basic. By knowing how to work with these values, you can create complex conditional statements that take into account multiple keys being pressed at once. Remember to use bitwise AND when working with hexadecimal values, and always pad the left side of your binary numbers to make them a multiple of four bits. With practice, you'll become proficient in using hexadecimal notation to represent keyboard key codes and other binary data.

Sources:
- [What are &H1, &H8000, etc.? | Tek-Tips] (https://www.tek-tips.com/threads/what-are-h1-h8000-etc.1080522/)
- [Why does font-size not inherit ? | Tek-Tips] (https://www.tek-tips.com/threads/why-does-font-size-not-inherit.1050326/)
- [Error: Only content controls are allowed directly in a ... - Tek-Tips] (https://www.tek-tips.com/threads/error-only-content-controls-are-allowed-directly-in-a-content-page.1504551/)
- [Coverage Paths | Tek-Tips] (https://www.tek-tips.com/threads/coverage-paths.1632312/)
- [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/)
- [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/)
- [Microsoft VBScript runtime error '800a01b6' | Tek-Tips] (https://www.tek-tips.com/threads/microsoft-vbscript-runtime-error-800a01b6.419805/)
- [Send 8-bit data over serial port; values over 3F are being set to 3F] (https://www.tek-tips.com/threads/send-8-bit-data-over-serial-port-values-over-3f-are-being-set-to-3f.1672795/)
- [how do i keep sections from moving when i minimize window?] (https://www.tek-tips.com/threads/how-do-i-keep-sections-from-moving-when-i-minimize-window.1611893/)
- [Forwarding one internal extension to External number | Tek-Tips] (https://www.tek-tips.com/threads/forwarding-one-internal-extension-to-external-number.1574548/)