03-29-2023, 05:10 AM
(This post was last modified: 03-29-2023, 05:13 AM by mnrvovrfc.
Edit Reason: Declared local variables JIC of OPTION _EXPLICIT
)
This is what I've designed and used for a long time:
Call:
"a$" then should give you a hexadecimal number of six digits padded by zeroes. "01869F", if you need the "&H" before it you will have to concatenate it separately.
Otherwise the second parameter should be greater than zero, for the number of digits you want in front of a decimal number.
Code: (Select All)
'this allows a negative value padded by zeroes after sign
'set "numdig" to negative value to convert "num" to hexadecimal
'eg. "numdig = -6" to convert "num" to 6-digit hexadecimal string
FUNCTION Zeroes$ (num AS LONG, numdig AS INTEGER)
DIM b$, hx AS LONG, sg AS LONG, v AS LONG
IF num < 0 THEN sg = -1: num = num * -1
IF numdig < 0 THEN hx = 1: numdig = numdig * -1 ELSE hx = 0
IF hx THEN
b$ = HEX$(num)
ELSE
b$ = LTRIM$(STR$(num))
END IF
v = numdig - LEN(b$)
IF v > 0 THEN b$ = STRING$(v, 48) + b$
IF sg = -1 THEN b$ = "-" + b$
Zeroes$ = b$
END FUNCTION
Call:
Code: (Select All)
DIM a$, nl AS LONG
nl = 99999
a$ = Zeroes$(nl, -6)
"a$" then should give you a hexadecimal number of six digits padded by zeroes. "01869F", if you need the "&H" before it you will have to concatenate it separately.
Otherwise the second parameter should be greater than zero, for the number of digits you want in front of a decimal number.