DAY 014: ASC
#2
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.
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.
Reply


Messages In This Thread
DAY 014: ASC - by SMcNeill - 11-18-2022, 04:31 PM
RE: DAY 014: ASC - by Pete - 11-18-2022, 06:49 PM
RE: DAY 014: ASC - by james2464 - 11-18-2022, 07:19 PM
RE: DAY 014: ASC - by Pete - 11-18-2022, 07:30 PM
RE: DAY 014: ASC - by mnrvovrfc - 11-18-2022, 11:30 PM
RE: DAY 014: ASC - by Pete - 11-19-2022, 12:09 AM
RE: DAY 014: ASC - by Pete - 11-19-2022, 12:14 AM
RE: DAY 014: ASC - by PhilOfPerth - 11-19-2022, 01:09 AM
RE: DAY 014: ASC - by SMcNeill - 11-19-2022, 06:27 AM



Users browsing this thread: 4 Guest(s)