VB Lect 02 - Intro To VB
VB Lect 02 - Intro To VB
You
Listen & understand
Welcome1.vb
Program Output
A few Good Programming Practices
• Comments
• Every program should begin with one or more comments
– Modules
• Begin each module with mod to make modules easier to identify
– Procedures
• Indent the entire body of each procedure definition one “level” of indentation
Steps
Project
name
File
location
Editor window
(containing
program code)
Module Module1
Sub Main() Code
‘START HERE
End Sub
End Module
Solution Explorer
Click
Module1.vb
to display its
properties
Properties window
File Name
property
Partially-typed member
Member list
Description of
highlighted member
IDE indicating a syntax error
Omitted parenthesis
character (syntax error)
Red underline
indicates a syntax
error
Error
description(s
Write() & WriteLine
Program
Output
Read(), ReadKey() & ReadLine()
Module Module1
Sub Main()
Console.ReadLine()
End Sub
End Module
ReadKey()
ReadLine()
Console – Basic Output
Module Module1
Sub Main()
System.Console.WriteLine("Hello world")
End Sub
End Module
System.Console
Console – Basic Output
Imports System
Module Module1
Sub Main()
Console.WriteLine("Hello
world")
End Sub
End Module
System.Console
Console – Basic Input & Store in Memory
Imports System
Module Module1
Sub Main()
Dim answer as integer
Console.Write ("Enter a number:")
answer = Console.ReadLine()
Console.Write ("You entered " & answer)
Memory name
Console.ReadKey()
End Sub
End Module
Console - Input Output (I/O)
Imports System
Module Module1
Sub Main()
Dim inputName as string
inputName = Console.ReadLine()
Imports System
Module Module1
Sub Main()
Console.Write ("Hello" & " " & "World.")
Console.ReadKey()
End Sub
End Module
Console Output – Clearing Screen
Imports System
Module Module1
Sub Main()
Console.Write ("Hello World.")
Console.Write ("Welcome ")
Console.Write ("to the bizarre world of programming.")
Console.ReadKey()
Console.Clear()
Console.ReadKey()
End Sub
End Module
Activity - Console Output
Sub Main()
Console.Beep()
Console.Write("Welcome to the world, ")
Console.Write("Adam." & Environment.NewLine)
Console.Write("As for you Eve, ")
Console.WriteLine("welcome to the bizarre world of VB programming.")
Console.Write("================================================")
Console.ReadKey()
Console.Clear()
Console.WriteLine("So, there you go...")
Console.ReadKey()
Console.Beep()
End Sub
Variables
x 1
y 2
Dim x As Integer = 1 z ?
Dim y As Integer = 2
Dim z As Integer
z = x + y
Console.WriteLine(z)
‘Console.WriteLine("Answer = {0}", z)
‘Console.WriteLine("Answer = " & z)
Text Size (How many characters)
Imports System
Module Module1
Sub Main()
Console.Write ("Enter your name:")
Console.ReadKey()
End Sub
End Module
Analyze: IPO
I = two integers
P = find average equation Get integer 1,
O = average (float/double) x and integer
2, y
Algorithm (Pseudocode):
1. Start
2. Get integer 1 and store in variable x. Avg=(x+y)/2
3. Get integer 2 and store in variable y.
4. Find the average, avg = (x + y) / 2
5. Display avg.
6. End Display avg
Output
Coding
Declaration with keyword Dim
These variables store integers value