You are on page 1of 7

Subject Grade Date Block week Unit/Lesson/Topic Study sheet

ICT 9 2 1 introduction to V.B 1 out of 16


Sequence instructions within a text-based programming language.
Learning Outcome
• Sequence instructions within a text-based programming
/Objective:
language to produce a program
Student Name: ………………………………………………………………………………………………………………………. Class 9

Contents
1. Introduction to programming with Visual Basic
2. Hello World Program
3. Difference between Console. Write () and Console.
WriteLine ()
4. To change the display window, you can use the
following console commands

Prepared by P a g e |1
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 introduction to V.B 1 out of 16
• Sequence instructions within a text-based programming
Objective:
language to produce a program
Student Name: ………………………………………………………………………………………………………………………. Class 9

Introduction to programming with Visual Basic:


• It is one of the high-level programming languages and designed to be easy to learn as
its commands and instructions use English language vocabulary and it can be used in
many
applications such as:
1- Windows applications
2- Web applications

• Visual Basic is a type-safe programming language that's designed to be easy to learn. A


console app takes input and displays output in a command-line window, also known as a
console.

Let’s start to create our first Program by VB.net


• Select File > New > Project.
• In the left pane, select Visual Basic Projects.
• In the right pane,
select Console
Application.
• Name the project and
specify the saving
location.

Prepared by P a g e |2
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 introduction to V.B 1 out of 16
• Sequence instructions within a text-based programming
Objective:
language to produce a program
Student Name: ………………………………………………………………………………………………………………………. Class 9

• A console application doesn’t have a user interface, so the first thing you’ll see is the
code editor’s window.

• The first line is telling us we're creating a module. It's just a way how we structure code
in VB.NET.
• The key will be the Sub Main() method for us, we'll write our code between this line and
the line with End Sub, i.e. the body. SubMain() is a reserved word, and Visual Basic
knows that this method must be executed as first after the application starts.

The second important element in the window is a green " " button in the upper bar, which
compiles and runs our program. You can try it, but our program will not do anything, just turn
terminate right away. You can also run the program with the F5 keyboard shortcut.

Prepared by P a g e |3
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 introduction to V.B 1 out of 16
• Sequence instructions within a text-based programming
Objective:
language to produce a program
Student Name: ………………………………………………………………………………………………………………………. Class 9

Example: Hello World Program


Console applications use the .NET Console class. The sample programs will use of:
[1] Console.Read() or Console.ReadLine() methods for input
[2] Console.Write() or Console.WriteLine() methods for output.
Module Module1
Sub Main()
Console.Write("Hello World!")
Console.ReadLine()
End Sub
End Module

This code would print “Hello World!”.


Let us explain each line in this code.
[1] Module Module1
Here, Module Module1 is used to define a module (Module1). The module (Module1) will
contain all the variables, methods, etc., based on our requirements.
[2] Sub Main()
Here, Sub Main() is used to define a method in our module (Module1).
• The keyword Sub is a procedure and it is helpful to write a series of Visual Basic
statements within Sub and End Sub statements.
• The name Main will refer to the name of our method in module (Module1). The Main()
method is the entry point of our console application.

Prepared by P a g e |4
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 introduction to V.B 1 out of 16
• Sequence instructions within a text-based programming
Objective:
language to produce a program
Student Name: ………………………………………………………………………………………………………………………. Class 9

[3] Console.WriteLine() / Console.ReadLine()


• Here, Console.WriteLine() and Console.ReadLine() methods are used to write a text
to the console and read the input from the console.
• The Console is a class of .NET Framework namespace System and WriteLine() and
ReadLine() are the methods of Console class.

You can run the program by pressing F5 or press on

Difference between Console.Write() and Console.WriteLine()


• Console.Write() is used to write data without printing the new line
• Console.WriteLine() is used to write data along with printing the new line.
Example:
Module Module1
Sub Main()
Console.Write("Hello World!")
Console.Write ("Hello ICT")
Console.ReadLine()
End Sub
End Module

Prepared by P a g e |5
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 introduction to V.B 1 out of 16
• Sequence instructions within a text-based programming
Objective:
language to produce a program
Student Name: ………………………………………………………………………………………………………………………. Class 9

Module Module1
Sub Main()
Console.WriteLine("Hello
World!")
Console.WriteLine ("Hello ICT")
Console.ReadLine()
End Sub
End Module

Console.Beep()
• Console.Beep(): Plays the sound of a beep through the console speaker.
Console.Beep (frequency As Integer, duration As Integer)
Play the sound of a beep of a specified frequency and duration through the console speaker
Example:
Module Module1
Sub Main()
Console.Beep (200, 5000)
End Sub
End Module

Prepared by P a g e |6
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 introduction to V.B 1 out of 16
• Sequence instructions within a text-based programming
Objective:
language to produce a program
Student Name: ………………………………………………………………………………………………………………………. Class 9

To change the display window, you can use the following console commands:
Module Module1
Sub Main)(
Console.Title = "User Define Console"
Console.BackgroundColor = ConsoleColor. DarkGray
Console.ForegroundColor = ConsoleColor.White
Console.WindowHeight = Console.LargestWindowHeight - 30
Console.WindowWidth = Console.LargestWindowWidth - 100
Console.Clear)(
Console.WriteLine("While Visual Studio .NET is the most popular method of
developing .NET applications.")
Console.ReadLine)(
End Sub
End Module

[1] Console.Title: To change the title of the window.


[2] Console.BackgroundColor: To change the background color of the window.
[3] Console.ForegroundColor: To change the color of the text.
[4] Console.WindowHeight = Console.LargestWindowHeight – 20
Sets the height of the console window area.
Console.WindowWidth = Console.LargestWindowWidth - [insert number of pixels from
the end of the screen]
[5] Console.WindowWidth = Console.LargestWindowWidth – 20
Sets the width of the console window.
Console.WindowHeight = Console.LargestWindowHeight - [insert number of pixels
from the end of the screen]
[6] Console.Clear)(: Clears the console buffer and corresponding console window of
displaybyinformation. Console.Clear() is used to clear the content of the console. After the
Prepared Page |7
console is cleared, the cursor goes to the top-left corner.

You might also like