Skip to main content

Cambridge IGCSE & O Level Computer Science Programming Book for Microsoft Visual Basic Sample

Page 20

We are working with Cambridge Assessment International Education towards endorsement of this title. Any references or material related to answers, grades, papers or examinations are based on the opinion of the author(s). CAMBRIDGE IGCSE™ & O LEVEL COMPUTER SCIENCE: PROGRAMMING BOOK

Step 1a Console.WriteLine("Hello World") Type the word ‘Console’ into the Main subroutine shown in the code window (see Figure 1.5).

LE

As you type you will notice that the IDE provides an autocompletion window listing all the code inputs or objects that match the letters you have typed. To autocomplete the entry, you can double click the correct item, or press the spacebar when the item is highlighted. This will speed up your coding as once you have typed in the first few characters of the instruction, the software will automatically highlight the closest match.

Figure 1.5: Autocompletion window

Step 1b .WriteLine("Hello World")

P

In Visual Basic, the functionality of a class is accessed by use of the dot symbol. When the program reads inputs and displays outputs, it makes use of the Console class. The Console class provides access to a library of methods that allow the user to interact with the console.

M

When Console has been completed type a dot symbol. This will show a list of all the available methods for the Console class (see Figure 1.6). The method we need is ‘WriteLine’, which will display text in the console window when the code is executed. The method must be passed with the required text: "Hello World". NOTE: The text to be included is in quotation marks to indicate that it is text and not a reference to another object.

Figure 1.6: Methods list

A

Step 2

Console.ReadKey()

S

The code  Console.WriteLine("Hello World") will display the required text in a console window when the application is run but the window will close as soon as the code has been executed. To prevent this, use the console ‘ReadKey’ method to pause the execution until a key is pressed on the keyboard.

8 Original material © Cambridge University Press 2021. This material is not final and is subject to further changes prior to publication.


Turn static files into dynamic content formats.

Create a flipbook
Cambridge IGCSE & O Level Computer Science Programming Book for Microsoft Visual Basic Sample by Cambridge International Education - Issuu