QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The RIGHT$ function returns a set number of characters in a STRING variable starting from the end and counting backwards.


RIGHT$(stringvalue$, numberofcharacters%)




Getting the right portion of a string value such as a person’s last name.

name$ = "Tom Williams"

Last$ = RIGHT$(name$, LEN(name$) - INSTR(name$, " ")) 'subtract space position from string length

PRINT Last$ 


Adding the leading zero in single digit HEX$ values using RIGHT to take the right two hexadecimal string digits.

SCREEN _NEWIMAGE(640, 480, 32) '32 bit screen modes ONLY!
red = 255
green = 0
blue = 128

Color32 red, green, blue
PRINT "Colored text"

SUB Color32 (R, G, B)
R = R AND &HFF: G = G AND &HFF: B = B AND &HFF '    limit values to 0 to 255
hexadecimal$ = "&HFF" + RIGHT$("0" + HEX$(R), 2) + RIGHT$("0" + HEX$(G), 2) + RIGHT$("0" + HEX$(B), 2)
PRINT hexadecimal$
COLOR VAL(hexadecimal$)

**Colored text**

Note: When a single hexadecimal digit is returned the resulting value will need the leading zero added. Otherwise the hexa- decimal value created will have a byte missing from the value. EX: Color &HFF000000 is valid while &HFF000 is not.

See Also