11-18-2022, 06:49 PM
Marty McFly would beg to differ, calling it the keyword of last month, but back to the present...
This is one I sometimes use if I want to compare a string by it's numerical value, mostly for simplicity sake but also if the program is mostly using numerical values and then interacts with strings where a numerical value of some character in the string is required. Yes, ASC() works with MID$() but if MID$ is not used, ASC() simply converts to a numeric value the first character of the string. The only exception is a null string, which will throw an error.
Examples.
Pete
This is one I sometimes use if I want to compare a string by it's numerical value, mostly for simplicity sake but also if the program is mostly using numerical values and then interacts with strings where a numerical value of some character in the string is required. Yes, ASC() works with MID$() but if MID$ is not used, ASC() simply converts to a numeric value the first character of the string. The only exception is a null string, which will throw an error.
Examples.
Code: (Select All)
WIDTH 80, 42
_CONTROLCHR OFF
FOR i = 1 TO 255
x$ = CHR$(i)
SELECT CASE x$
CASE "a" TO "z"
PRINT i; x$
END SELECT
NEXT
SLEEP
CLS
x = ASC("a") - 1
FOR j = 1 TO 26
PRINT j; CHR$(j + x)
NEXT
x$ = "Pete" ' ASC() will read the first character: "P"
IF ASC(x$) < 127 THEN PRINT "Okay!" ' It can be used to identify a range like 0 - 126.
SLEEP
x$ = "" ' ASC will not accept a null string.
PRINT ASC(x$) ' This will error out.
Pete
If eggs are brain food, Biden takes his scrambled.