Download QBASIC Programming for Kids

Transcript
If you need to convert a string to all uppercase or all lowercase, UCASE$() and LCASE$
() are exactly what you need.
A$ = "Fly Away With Me"
PRINT A$
PRINT UCASE$(A$)
PRINT LCASE$(A$)
You can use UCASE$() and LCASE$() to do "case-insensitive" tests. In other words,
upper and lower case are ignored. Here's an improvement to a previous program.
CLS
INPUT "Enter your name: ", Name$
IF LCASE$(Name$) = "mike" THEN
PRINT "Go Away!"
ELSE
PRINT "Hello, "; Name$; ". How are you today?"
END IF
In this new version, the user can type "mike", "Mike" or even "MIKE" and the name will
be recognized.
STRING$() and SPACE$()
Let's say you need to print 20 stars on the screen in a line. You could do it like this:
PRINT "********************"
But, there has got to be a better way. How about with a FOR loop?
FOR I = 1 to 20
PRINT "*";
NEXT I
PRINT
That works well, but QBASIC provides an even easier way to do this with STRING$().
PRINT STRING$(20, "*")
The first argument to STRING$() is the number of times you want a character repeated.
The second argument is the character you want to repeat. So, STRING$(20, "*") means
"give me 20 stars".
If you want to print a lot of spaces, you could do it with STRING$():
PRINT "A"; STRING$(20, " "); "B"
Or you can use SPACE$().