0% found this document useful (0 votes)
54 views8 pages

Tutorial - 1 First Program Code: Main .Writeline .Readline

The document contains 5 tutorials that demonstrate basic concepts in Visual Basic programming including: 1. Writing a simple first program that displays text and uses Console.ReadLine() to pause the program. 2. Explaining different data types like integers, characters, and logical operators. 3. Demonstrating how to declare and assign values to variables of different data types. 4. Showing how to perform basic math operations on variables using operators like addition and modulus. 5. Getting user input using Console.ReadLine() and displaying it.

Uploaded by

SaadAmin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views8 pages

Tutorial - 1 First Program Code: Main .Writeline .Readline

The document contains 5 tutorials that demonstrate basic concepts in Visual Basic programming including: 1. Writing a simple first program that displays text and uses Console.ReadLine() to pause the program. 2. Explaining different data types like integers, characters, and logical operators. 3. Demonstrating how to declare and assign values to variables of different data types. 4. Showing how to perform basic math operations on variables using operators like addition and modulus. 5. Getting user input using Console.ReadLine() and displaying it.

Uploaded by

SaadAmin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

TUTORIAL -1

FIRST PROGRAM

CODE
This is the
Module Module1 comment or

Sub Main()
Console.WriteLine("This is my first program")

Console.ReadLine() '--------------------------If you do not write this command


the program will run but screen will disappear immediately. This line wait/hold for user
to press any key or to give any input

Console.WriteLine("Press Enter again")

Console.ReadLine()

Console.WriteLine("Press Enter one more time")

Console.ReadLine()

End Sub

End Module

OUTPUT

This is my first program <-

Press Enter again <-

Press Enter one more time <-

*END*
TUTORIAL - 2

PRIMITIVE DATA TYPES AND ERRORS

Data
Types

Logical
Numbers Characters
Operators

Real
Integers Character Strings Boolean
Numbers

Byte Short Integer Long Double Float

ERRORS
1. Syntax Errors (Error in coding syntax) can be checked as follows:

2. Run time Errors (Will be discussed later)


3. Logical Errors (Will be discussed later)
TUTORIAL – 3

VARIABLES

There is no possible way to create a program without variable.


Module Module1

Sub Main()

Dim MYNUM1 As Integer ' The word "Dim" is used to initiate the variable. Here we
have a variable "MYNUM" whose data type is taken as integer. It means it will deal with
integers

MYNUM1 = 0 ' In this statement we have assigned a value to an integer

Console.WriteLine(MYNUM1) ' This command will show only the value of variable
"MYNUM1"

Console.ReadLine()

Dim MYNUM2 As Integer = 0 ' Instead of using another line we can assign the value
to variable in the same line

Console.WriteLine(MYNUM2)

Console.ReadLine()

MYNUM2 = 4 ' Here we have assigned a new value to a variable

Console.WriteLine(MYNUM2) ' Now system will print the latest value of the
variable which is 4 and not 0

Console.ReadLine()

Dim STRING1 As String = "Hello SAAD" ' String variable is used here

Console.WriteLine(STRING1) 'Value of String Variable is reflected

Console.ReadLine()

Dim CHAR1 As Char = "A" ' Character variable is used

Console.WriteLine(CHAR1)

Console.ReadLine()

Dim DOUBLE1 As Double = 5.4 ' Value of double variable is reflected

Console.WriteLine(DOUBLE1)

Console.ReadLine()

Dim BOOL As Boolean = False ' Value of Boolean (True/False) is reflected


Console.WriteLine(BOOL)

Console.ReadLine()

Dim MYNUM3 As Integer = 300

MYNUM3.ToString() ' This is used to convert number to string. In programming its


a good practice to convert num to string

Console.WriteLine(MYNUM3)

Console.ReadLine()

Dim MYNUM4 As Integer = 900

Console.WriteLine(MYNUM4.ToString()) ' Another way to convert number to string

Console.ReadLine()

Dim NEWVAR As Boolean = True

Console.WriteLine(NEWVAR.ToString())

Console.ReadLine()

End Sub

End Module
TUTORIAL – 4

MATH OPERATORS

Module Module1

Sub Main()
Dim NUM1 As Integer = 5
Dim NUM2 As Integer = 5
Dim NUM3 As Integer = Nothing
Console.WriteLine(NUM1 + NUM2) 'Addition
Console.WriteLine(NUM1 - NUM2) 'Subtraction
Console.WriteLine(NUM1 * NUM2) 'Multiplication
Console.WriteLine(NUM1 ^ 2) 'Power/Exponents
Console.WriteLine(NUM1 / NUM2) 'Division
Console.WriteLine(NUM1 Mod NUM2) 'Modulus. That returns the remainder

Console.WriteLine(NUM1 / 4) ' This line will give the caculation 1.25. the
decimals are not related to any variable. This is the calculated result.

NUM3 = NUM1 / 4 'This will not give the output 1.25 as the value will be stored
in NUM3 which is integer and integer value cannot be in decimals

Console.WriteLine(NUM3)

NUM3 = NUM1 Mod 2

Console.WriteLine(NUM3)

Console.ReadLine()

' ******************** MORE ON MATH OPERATORS ********************

Console.WriteLine("NOW MORE ON MATH OPERATORS")

Dim MYDOUBLE As Double = 11

Console.WriteLine(MYDOUBLE) 'This will print MYDOUBLE value which is 10

Console.WriteLine(MYDOUBLE + 10) 'This will add 10 to MYDOUBLE value which was 11


so it will print 21

Console.WriteLine(MYDOUBLE) 'This will not change the variable value to 21 as no


new value is initialized

MYDOUBLE = MYDOUBLE + 10 ' Now new value wil be stored for MYDOUBLE

Console.WriteLine(MYDOUBLE)

MYDOUBLE = 11
Console.WriteLine(MYDOUBLE)

MYDOUBLE += 10 ' This is equivalent to MYDOUBLE = MYDOUBLE + 1


Console.WriteLine(MYDOUBLE)

Console.ReadLine()

End Sub

End Module
TUTORIAL – 5

GETTING USER INPUT

Module Module1

Sub Main()

Dim USERNAME As String = Nothing


Dim AGE As Integer = Nothing
Dim SALARY As Double = Nothing

Console.WriteLine("What is your Name:")

USERNAME = Console.ReadLine() ' Getting user input. Readline will wait for your
input and USERNAME will store the entered value

Console.WriteLine("What is your Age:")


AGE = Console.ReadLine()

Console.WriteLine("What is your Salary:")


SALARY = Console.ReadLine()

Console.WriteLine("Your Name is:" & USERNAME) ' This will print the value of the
variable. "&" is used to concatenate the text and variables

Console.WriteLine("Your Age is:" & AGE)


Console.WriteLine("Your Salary is:" & SALARY)
Console.ReadLine()

Console.WriteLine() ' Go to next new line

Console.Write("Your Name is:" & USERNAME) ' Instead of WriteLine we used Write.
This will not take the user to next line and print on the same line

Console.Write(" Your Age is:" & AGE)


Console.Write(" Your Salary is:" & SALARY)
Console.ReadLine()

Console.WriteLine()
Console.Write("Your Name is:" & USERNAME & " Your Age is:" & AGE & " Your
Salary is:" & SALARY) ' This is another way to write on the same line instead of using
three different line command for "Write"

Console.ReadLine()

End Sub

End Module

You might also like