G9 - Block 2 - Week 1 - WS3 - Variables Variable Declaration
G9 - Block 2 - Week 1 - WS3 - Variables Variable Declaration
Contents
1. Variables in Visual Basic
2. Variable Declaration
3. Rules for forming variable names
4. Variable Initialization in VB.Net
5. Ask user to enter the value.
6. Comments in Code (Visual Basic)
Prepared by P a g e |1
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 Variables & variable declaration 4 out of 16
Objective: • Assign values to variable or constants
Student Name: ………………………………………………………………………………………………………………………. Class 9
Variable Declaration
• A variable must be declared before it’s used. The declaration of a variable means
specifying its data type.
• If you do not declare the precise data type of a variable, it will be of type Object.
• In Visual Basic, a variable is declaring as follows:
EX:
Dim Name As String ‘this statement declares a string variable.
Dim Num As Integer ‘this statement declares an integer variable.
Dim y As Boolean
Prepared by P a g e |2
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 Variables & variable declaration 4 out of 16
Objective: • Assign values to variable or constants
Student Name: ………………………………………………………………………………………………………………………. Class 9
The Console class in the System namespace provides a function read Line for accepting
input from the user and store it into a variable. For example,
Dim Name As String
Name = Console.ReadLine()
Module Module1
Sub Main)(
Dim message As String
Console.Write("Enter Your Message: ")
message = Console.ReadLine()
Console.WriteLine)(
Console.WriteLine("Your Message: " & message)
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following result (assume
the user inputs Hello ICT) −
Prepared by P a g e |4
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 Variables & variable declaration 4 out of 16
Objective: • Use comment in visual basic.
•
Student Name: ………………………………………………………………………………………………………………………. Class 9
The {0} is a feature of the .Net APIs. It represents a position within a string which will
later be replaced with a value. The {0} refers to the first value passed to the function,
{1} the second and so on. This means that all the below operations are roughly
equivalent
Prepared by P a g e |5