Kyle Chau
Kyle Chau

Reputation: 21

Syntax error with UCASE$?

Not sure what this means. It says it's a syntax error with UCASE$ but can I not put letter$ in there?

CLS
PRINT "Do you want lower case or upper case? (U/L)"
DO
    CASED$ = INKEY$
LOOP UNTIL CASED$ = "U" OR CASED$ = "L"



IF CASED$ = "L" THEN
    FOR char = 1 TO 26
        READ letter$
        PRINT letter$; " = "; ASC(letter$)
        SLEEP 1
    NEXT char
ELSE
    FOR char = 1 TO 26
        READ letter$
        UCASE$(letter$)
        PRINT letter$; " = "; ASC(letter$)
        SLEEP 1
    NEXT char
END IF
DATA a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z

Upvotes: 2

Views: 270

Answers (1)

Robert Talada
Robert Talada

Reputation: 372

UCASE$ is a function that returns a string. You need to pass what it returns into a variable. A common behavior of most built-in functions in BASIC is that they can stand in place of a variable or expression.

letter$ = UCASE$(letter$)

To demonstrate why this is, try

a$ = "h"
PRINT a$, UCASE$(a$)

in a new program. As you can see, UCASE$ itself becomes the new string instead of manipulating the original string. If you want to preserve the result of the function, you must pass it into a variable.

Upvotes: 3

Related Questions