Simple input and strings

        Okay, now that you know how to print text and variables, we can talk about how you can get input from a user, like a number or a word, or anything really. More in-depth input will be discussed later in this tutorial, but for now we will just deal with simple things.
Getting input from a user is a lot like printing output to the screen, only backwards.
Example:

        INPUT "Please input a number"; A1%

Output:

        Please input a number?

and then you put a number in and press ENTER, and A1% will now have the value of that number.         Notice that there is a quesion mark already put behind the text for you. You can get rid of this question mark by using a (,) instead of a (;).

        Now we come to strings. Strings are just like any other variable in QBasic, except that you cannot perform mathematical operations on them and all string variables must end with a '$'. For example a$, is a valid string variable. A string variable can store not only numbers, but any printable character.
Example:

        INPUT "Please Enter your name: ", name$
        PRINT "Your Name is:"; name$

Output:

        Please Enter your name: Nable
        Your Name is: Nable

        One thing to note about string variables, is that unless given a value they are 'empty', that is to say, they don't contain any characters and will not print anything to the screen if you try.
        There are many ways to manipulate strings, but they will be discussed in later sections of the tutorial. You should now have a good feel for the general way that output is printed to the screen, how input is obtained from the user and how variables work. These are important concepts. As the tutoral progresses it will be assumed that you understand the general form of input and output. The examples listed above should serve as a good basis.

    Back         Tutorial Part 1         Next