A-level Computing 2009/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Fundamentals of Programming/Input and output





An important part of computer code is allowing your user to input data into the program, things such as text, key presses or even a data feed from a motion sensor games controller.

Once the data is in the program you want the system to output responses, these may take the form of output to a screen: graphics, text, output to a sound device, printed documents or data output to another program.

For this unit you need to be familiar with a few input and output commands. The little black box that appears on your screen is called the console. In VB.NET all the commands to read and write from this are accessed from the  command, let's take a look at some:

Outputs
For the AS course it is unlikely you will need anything beyond the print to screen command and the write to file command (see later). There are two write to screen commands that you should be familiar with: Let's see an example of this in action: This would output the following:

Hello how are you?

I'm fine thank

you.

Notice the difference between a  and a   command.

We can do a lot of things with the  command. If you are using Visual Studio then type the following: Up should pop some suggestions. Play around with  and

There is also a command to output a small and annoying sound, it's unlikely you'll need to know this for the exam, and your teachers will most likely hate it.

Find out more about the  command on the MSDN website

Inputs
To make your program interactive you'll need your user to input commands, for the exam these will most likely be text instructions or reading from a file (covered later). You might look at buttons and games controllers next year. In VB.NET there are two types of input command that you need to know: Let's take a look at a quick example of where this might be used:

Please insert you name: Ali Hello Ali

There is also the command that reads in a single character. Take a look at this example:

Please select from options 1,2,3 or 4:

4

You chose : 4

What does the following code output:

The

Catsat on

the mat

The average age

of a combat soldier in Vietnam was 19

Write code to display the following to the screen:

My favourite colours:

Red

Blue

What would the following look like: for the input:

John

16

Enter your name: John

Enter your age: 16

Hello 16. You are John years old

Whoops! Fix this: