Exploring Hexadecimal Values in VB Classic

By Eleanor Hexwell | Created on 2025-09-01 07:26:09

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

0:00 / 0:00
The programming world is filled with various numerical systems, and hexadecimal (hex) is one of the most widely used. In this context, we are going to explore how VB Classic handles hex values, specifically when dealing with keyboard inputs. When working with keyboard inputs, you may come across hexadecimal values prefixed with an ampersand (&), such as &H1 or &H8000. But what do these actually represent? As ADoozer mentioned in the thread, "&H" indicates that a number is written in hexadecimal. In other words, it's a way of representing numbers using base 16 instead of the more common base 10 (decimal). So, &H1 would be equivalent to decimal 1, and &H8000 would be equivalent to decimal 32768. Now, let's dive into how VB Classic handles these hex values when dealing with keyboard inputs. The GetKeyState function is used to determine the state of a virtual key. This function returns a short integer value that can be bitwise ANDed with a specific hex value to check for its state. As Sheco explained in the thread, if we want to check whether the ALT key has been pressed or not, we would use the value &H12 (which is the virtual key code for the ALT key) and assign it the high-order bit (&H8000). This is because the GetKeyState function sets the high-order bit when a key is down. To demonstrate this concept, let's consider an example where we want to check if both the ALT key and the 'X' key are pressed simultaneously. We can use the following code: ``` 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) tempVKCodeHolder = correctedInputValues(CInt(Trim(HookStruct.vkCode))) 'Takes the interpreted keyboard input value and translates it to its proper ascii value. If ((IsAlt = True) And (tempVKCodeHolder = 88)) Then 'If ALT and "X" are pressed at the same time, 'the user's data is Copied to the Clipboard. Clipboard.Clear Clipboard.SetText (strUserInput) Exit Function End If ``` In this code, we first declare a constant for the virtual key code of the ALT key (&H12). We then define a type for KBDLLHOOKSTRUCT and use it to get the state of the ALT key by performing a bitwise AND operation with &H8000. This checks if the high-order bit is set, indicating that the key is down. By combining this understanding of hex values in VB Classic with keyboard inputs, we can create more complex programs that respond to specific user input combinations.

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/)
- [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/)
- [Why does font-size not inherit ? | Tek-Tips] (https://www.tek-tips.com/threads/why-does-font-size-not-inherit.1050326/)
- [Forwarding one internal extension to External number | Tek-Tips] (https://www.tek-tips.com/threads/forwarding-one-internal-extension-to-external-number.1574548/)
- [Microsoft VBScript runtime error '800a01b6' | Tek-Tips] (https://www.tek-tips.com/threads/microsoft-vbscript-runtime-error-800a01b6.419805/)
- [How to Display list of links | Tek-Tips] (https://www.tek-tips.com/threads/how-to-display-list-of-links.1217411/)
- [Vb6 Excel Set Range NumberFormat | Tek-Tips] (https://www.tek-tips.com/threads/vb6-excel-set-range-numberformat.1702432/)
- [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/)
- [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/)