Useful Constants - SMcNeill - 12-16-2022
Code: (Select All) 'Common CONST which I tend to find very useful to plug into programs
Const True = -1%%
Const False = 0%%
$If WIN Then
Const Slash = "\"
$Else
Const Slash = "/"
$End If
Dim Shared As String MyAppPath, MyAppName, MyAppFullPath, Quote ' These are shared strings, but they need to be gotten at the start of a program.
MyAppPath = _CWD$ ' I'll grab them here and just pretend that they're CONST.
MyAppName = Mid$(Command$(0), _InStrRev(Command$(0), Slash$) + 1) 'Shhh... don't tell anyone. It'll be our little secret!
MyAppFullPath = MyAppPath + Slash + MyAppName
Quote = Chr$(34)
'Variable Type Limits
Const Bit_Min = -1`, Bit_Max = 0`
Const UBit_Min = 0~`, UBit_Max = 1~`
Const Byte_Min = -128%%, Byte_Max = 127%%, Int8_Min = -128%%, Int8_Max = 127%%
Const UByte_Min = 0~%%, UByte_Max = 255~%%, UInt8_Min = 0~%%, UInt_Max = 255~%%
Const Integer_Min = -32768%, Integer_Max = 32767%, Int16_Min = -32768%, Int16_Max = 32767%
Const UInteger_Min = 0~%, UInteger_Max = 65535~%, UInt16_Min = 0~%, UInt16_Max = 65535~%
Const Long_Min = -2147483648&, Long_Max = 2147483647&, Int32_Min = -2147483648&, Int32_Max = 2147483647&
Const ULong_Min = 0~&, ULong_Max = 4294967295~&, UInt32_Min = 0~&, UInt32_Max = 4294967295~&
Const Integer64_Min = -9223372036854775808&&, Integer64_Max = 9223372036854775807&&, Int64_Min = -9223372036854775808&&, Int64_Max = 9223372036854775807&&
Const UInteger64_Min = 0~&&, UInteger64_Max = 18446744073709551615~&&, UInt64_Min = 0~&&, UInt64_Max = 18446744073709551615~&&
Const Single_Min! = -2.802597E-45, Single_Max! = 3.402823E+38
Const Double_Min# = -4.490656458412465E-324, Double_Max = 1.797693134862310E+308
Const Float_Min## = -1.18E-4932, Float_Max## = 1.18E+4932
$If 32BIT Then
Const Offset_Min = -2147483648&, Offset_Max = 2147483647&
Const UOffset_Min = 0~&, UOffset_Max = 4294967295~&
$Else
Const Offset_Min = -9223372036854775808&&, Offset_Max = 9223372036854775807&&
Const UOffset_Min = 0~&&, UOffset_Max = 18446744073709551615~&&
$End If
'Keyhit Values
Const Key_Backspace = 8
Const Key_Tab = 9
Const Key_Enter = 13
Const Key_Shift = 16
Const Key_Control = 17
Const Key_Alt = 18
Const Key_CapsLock = 20
Const Key_ESC = 27
Const Key_Space = 32
Const Key_LeftShift = 100304
Const Key_RightShift = 100303
Const Key_LeftCtrl = 100306
Const Key_RightCtrl = 100305
Const Key_LeftAlt = 100308
Const Key_RightAlt = 100307
Const Key_PageUp = 18688
Const Key_PageDown = 20736
Const Key_LeftArrow = 19200
Const Key_RightArrow = 19712
Const Key_UpArrow = 18432
Const Key_DownArrow = 20480
Const Key_F1 = 15104
Const Key_F2 = 15360
Const Key_F3 = 15616
Const Key_F4 = 15872
Const Key_F5 = 16128
Const Key_F6 = 16384
Const Key_F7 = 16640
Const Key_F8 = 16896
Const Key_F9 = 17152
Const Key_F10 = 17408
Const Key_F11 = 34048
Const Key_F12 = 34304
Const Key_Home = 18176
Const Key_Delete = 21248
Const Key_Insert = 20992
Const Key_Win = 100311
Const Key_Menu = 100319
Const Key_PrintScreen = 900044
Const Key_ScrollLock = 100302
Const Key_Accent = 96
Const Key_Tilde = 126
Const Key_1 = 49
Const Key_2 = 50
Const Key_3 = 51
Const Key_4 = 52
Const Key_5 = 53
Const Key_6 = 54
Const Key_7 = 55
Const Key_8 = 56
Const Key_9 = 57
Const Key_0 = 48
Const Key_Minus = 45, Key_Dash = 45, Key_Subtract = 45
Const Key_Equal = 61
Const Key_Exclaim = 33
Const Key_At = 64
Const Key_Pound = 35
Const Key_Dollar = 36
Const Key_Percent = 37
Const Key_Power = 94, Key_Caret = 94
Const Key_And = 38
Const Key_Star = 42, Key_Multiply = 42
Const Key_LeftParen = 40
Const Key_RightParen = 41
Const Key_Underscore = 95
Const Key_Plus = 43, Key_Add = 43
Const Key_LowerCase = 32 ' Add to key values to get lowercase characters
Const Key_A = 65, Key_A_Low = 97 'for example, 65 is A. 65 + 32 = a (97)
Const Key_B = 66, Key_B_Low = 98 'So it's basically IF Key_B AND Key_LowerCase THEN 'it's a "b"
Const Key_C = 67, Key_C_Low = 99
Const Key_D = 68, Key_D_Low = 10
Const Key_E = 69, Key_E_Low = 101
Const Key_F = 70, Key_F_Low = 102
Const Key_G = 71, Key_G_Low = 103
Const Key_H = 72, Key_H_Low = 104
Const Key_I = 73, Key_I_Low = 105
Const Key_J = 74, Key_J_Low = 106
Const Key_K = 75, Key_K_Low = 107
Const Key_L = 76, Key_L_Low = 108
Const Key_M = 77, Key_M_Low = 109
Const Key_N = 78, Key_N_Low = 110
Const Key_O = 79, Key_O_Low = 111
Const Key_P = 80, Key_P_Low = 112
Const Key_Q = 81, Key_Q_Low = 113
Const Key_R = 82, Key_R_Low = 114
Const Key_S = 83, Key_S_Low = 115
Const Key_T = 84, Key_T_Low = 116
Const Key_U = 85, Key_U_Low = 117
Const Key_V = 86, Key_V_Low = 118
Const Key_W = 87, Key_W_Low = 119
Const Key_X = 88, Key_X_Low = 110
Const Key_Y = 89, Key_Y_Low = 111
Const Key_Z = 90, Key_Z_Low = 112
Const Key_LeftBrace = 91, Key_LeftBracket = 91
Const Key_RightBrace = 93, Key_RightBracket = 93
Const Key_BackSlash = 92
Const Key_LeftCurly = 123
Const Key_RightCurly = 125
Const Key_Pipe = 124
Const Key_Semicolon = 59
Const Key_Colon = 58
Const Key_Apostrophy = 39
Const Key_Quote = 34
Const Key_Comma = 44
Const Key_Period = 46, Key_Dot = 46
Const Key_ForwardSlash = 47, Key_Slash = 47
Const Key_LessThan = 60
Const Key_GreaterThan = 62
Const Key__QuestionMark = 63, Key_Question = 63
'Note that the following keys are listed as 900000+. These are KeyHit codes from my KeyHit library and not _KEYHIT values.
'For _KEYHIT values, drop the 900 in front, and QB64-PE will report the other values on a KEYUP event only.
'So you can read Mute, but it'll *ONLY* read as -173, and that's *only* when you release the key.
'None of these read at all for us on keydown events.
Const Key_Mute = 900173
Const Key_VolUp = 900174
Const Key_VolDown = 900175
Const Key_Stop = 900178
Const Key_Rewind = 900177
Const Key_Forward = 900176
Const Key_Play = 900179
'And for the following, these are also 900000+ KeyHit library codes. These are mouse events that QB64-PE simply fails to recognize
'at all. These neither register with _KEYHIT as a keydown, nor a keyup event. As far as _KEYHIT is concerned, these keys
'simply don't exist!
Const Key_LeftMouse = 900001
Const Key_RightMouse = 900002
Const Key_MiddleMouse = 900004
Const Key_Mouse4 = 900005
Const Key_Mouse5 = 900006
'Inkey$ Codes
Dim Shared As String Inkey_Backspace: Inkey_Backspace = Chr$(8)
Dim Shared As String Inkey_Tab: Inkey_Tab = Chr$(9)
Dim Shared As String Inkey_Enter: Inkey_Enter = Chr$(13)
Dim Shared As String Inkey_ESC: Inkey_ESC = Chr$(27)
Const Inkey_Space = " "
Dim Shared As String Inkey_PageUp: Inkey_PageUp = MKI$(18688)
Dim Shared As String Inkey_PageDown: Inkey_PageDown = MKI$(20736)
Dim Shared As String Inkey_LeftArrow: Inkey_LeftArrow = MKI$(19200)
Dim Shared As String Inkey_RightArrow: Inkey_RightArrow = MKI$(19712)
Dim Shared As String Inkey_UpArrow: Inkey_UpArrow = MKI$(18432)
Dim Shared As String Inkey_DownArrow: Inkey_DownArrow = MKI$(20480)
Dim Shared As String Inkey_F1: Inkey_F1 = MKI$(15104)
Dim Shared As String Inkey_F2: Inkey_F2 = MKI$(15360)
Dim Shared As String Inkey_F3: Inkey_F3 = MKI$(15616)
Dim Shared As String Inkey_F4: Inkey_F4 = MKI$(15872)
Dim Shared As String Inkey_F5: Inkey_F5 = MKI$(16128)
Dim Shared As String Inkey_F6: Inkey_F6 = MKI$(16384)
Dim Shared As String Inkey_F7: Inkey_F7 = MKI$(16640)
Dim Shared As String Inkey_F8: Inkey_F8 = MKI$(16896)
Dim Shared As String Inkey_F9: Inkey_F9 = MKI$(17152)
Dim Shared As String Inkey_F10: Inkey_F10 = MKI$(17408)
Dim Shared As String Inkey_F11: Inkey_F11 = MKI$(34048)
Dim Shared As String Inkey_F12: Inkey_F12 = MKI$(34304)
Dim Shared As String Inkey_Home: Inkey_Home = MKI$(18176)
Dim Shared As String Inkey_Delete: Inkey_Delete = MKI$(21248)
Dim Shared As String Inkey_Insert: Inkey_Insert = MKI$(20992)
Const Inkey_Accent = "`"
Const Inkey_Tilde = "~"
Const Inkey_1 = "1"
Const Inkey_2 = "2"
Const Inkey_3 = "3"
Const Inkey_4 = "4"
Const Inkey_5 = "5"
Const Inkey_6 = "6"
Const Inkey_7 = "7"
Const Inkey_8 = "8"
Const Inkey_9 = "9"
Const Inkey_0 = "0"
Const Inkey_Minus = "-", Inkey_Dash = "-", Inkey_Subtract = "-"
Const Inkey_Equal = "="
Const Inkey_Exclaim = "!"
Const Inkey_At = "@"
Const Inkey_Pound = "#"
Const Inkey_Dollar = "$"
Const Inkey_Percent = "%"
Const Inkey_Power = "^", Inkey_Caret = "^"
Const Inkey_And = "&"
Const Inkey_Star = "*", Inkey_Multiply = "*"
Const Inkey_LeftParen = "("
Const Inkey_RightParen = ")"
Const Inkey_Underscore = "_"
Const Inkey_Plus = "+", Inkey_Add = "+"
Const Inkey_A = "A", Inkey_A_Low = "a" 'for example, 65 is A. 65 + 32 = a (97)
Const Inkey_B = "B", Inkey_B_Low = "b" 'So it's basically IF Inkey_B AND Inkey_LowerCase THEN 'it's a "b"
Const Inkey_C = "C", Inkey_C_Low = "c"
Const Inkey_D = "D", Inkey_D_Low = "d"
Const Inkey_E = "E", Inkey_E_Low = "e"
Const Inkey_F = "F", Inkey_F_Low = "f"
Const Inkey_G = "G", Inkey_G_Low = "g"
Const Inkey_H = "H", Inkey_H_Low = "h"
Const Inkey_I = "I", Inkey_I_Low = "i"
Const Inkey_J = "J", Inkey_J_Low = "j"
Const Inkey_K = "K", Inkey_K_Low = "k"
Const Inkey_L = "L", Inkey_L_Low = "l"
Const Inkey_M = "M", Inkey_M_Low = "m"
Const Inkey_N = "N", Inkey_N_Low = "n"
Const Inkey_O = "O", Inkey_O_Low = "o"
Const Inkey_P = "P", Inkey_P_Low = "p"
Const Inkey_Q = "Q", Inkey_Q_Low = "q"
Const Inkey_R = "R", Inkey_R_Low = "r"
Const Inkey_S = "S", Inkey_S_Low = "s"
Const Inkey_T = "T", Inkey_T_Low = "t"
Const Inkey_U = "U", Inkey_U_Low = "u"
Const Inkey_V = "V", Inkey_V_Low = "v"
Const Inkey_W = "W", Inkey_W_Low = "w"
Const Inkey_X = "X", Inkey_X_Low = "x"
Const Inkey_Y = "Y", Inkey_Y_Low = "y"
Const Inkey_Z = "Z", Inkey_Z_Low = "z"
Const Inkey_LeftBrace = "[", Inkey_LeftBracket = "["
Const Inkey_RightBrace = "]", Inkey_RightBracket = "]"
Const Inkey_BackSlash = "\"
Const Inkey_LeftCurly = "{"
Const Inkey_RightCurly = "}"
Const Inkey_Pipe = "|"
Const Inkey_Semicolon = ";"
Const Inkey_Colon = ":"
Const Inkey_Apostrophy = "'"
Dim Shared As String Inkey_Quote: Inkey_Quote = Chr$(34)
Const Inkey_Comma = ","
Const Inkey_Period = ".", Inkey_Dot = "."
Const Inkey_ForwardSlash = "/", Inkey_Slash = "/"
Const Inkey_LessThan = "<"
Const Inkey_GreaterThan = ">"
Const Inkey_QuestionMark = "?", Inkey_Question = "?"
A list of the various CONST that I find myself endlessly using in my programs. Gathered in one spot like this, they make for an easy $INCLUDE at the top of my code, and then I can make use of the names and values without having to always look up a keycode chart somewhere for my needs.
For example, what's the minimum value you can use for a LONG? Long_Min!
What's the input value of the left arrow key with Inkey$? Inkey_LeftArrow!
What's the keydown value of the left shift key? Key_LeftShift!
Names of things that are much easier to remember than their actual values -- that's all this is. Free to use, abuse, and alter as wanted/needed.
Enjoy, guys.
RE: Useful Constants - Pete - 12-16-2022
And for our Windows API users, don't forget about our special CONSTANT companion offer, 500 Free Constants for Win32 API...
https://qb64phoenix.com/forum/showthread.php?tid=1096&pid=9602&highlight=constants#pid9602
Pete
CONST Pete = PITASCII
|