= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen"> = 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen">
Download presentation
Presentation is loading. Please wait.
1
VB.Net Programming Console Application
Walkthrough Example : Student Grades
2
Narrative Memory Screen Code
The first line of the program indicates the main( ) procedure. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen
3
Narrative Memory Screen Code This line is a comment.
Comment lines are for information only. They are ignored by the compiler. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen
4
Code Narrative Memory Screen 80 60 40 DIST MERIT PASS
These three lines create three CONSTANTS and name them DIST, MERIT and PASS. CONSTANT means the value will not change during the program. Values are set now and can not be changed. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40
5
Code Narrative Memory Screen 80 60 40 DIST MERIT PASS Mark
A variable is created called Mark. This will store the student mark when entered by the user. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark
6
Code Narrative Memory Screen 80 60 40 DIST MERIT PASS Mark
This line Clears the console screen. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark
7
Code Narrative Memory Screen 80 60 40 DIST MERIT PASS Mark
This line displays a prompt for the user to enter a student mark. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark Please enter the first mark :
8
Code Narrative Memory Screen 80 60 40 35 DIST MERIT PASS Mark
The user enters a mark and it is stored in the memory variable Mark. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark 35 Please enter the first mark : 35
9
Code Narrative Memory Screen 80 60 40 35 DIST MERIT PASS Mark
The while loop starts. All code between while and end while is in the loop. The loop will continue while the value in Mark is greater than or equal to 0. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark 35 Please enter the first mark : 35
10
Code Narrative Memory Screen 80 60 40 35 DIST MERIT PASS Mark
This statement checks the variable Mark is greater than or equal to the constant DIST. If it is then the text in quotes is printed to the console. If it is not then the next ElseIF is run…… Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark 35 Please enter the first mark : 35
11
Code Narrative Memory Screen 80 60 40 35 DIST MERIT PASS Mark
This statement checks the variable Mark is between the MERIT and DIST values. If it is then the text in quotes is printed to the console. If it is not then the next ElseIF is run…… Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark 35 Please enter the first mark : 35
12
Code Narrative Memory Screen 80 60 40 35 DIST MERIT PASS Mark
This statement checks the variable Mark is between the PASS and MERIT values. If it is then the text in quotes is printed to the console. If it is not then the Else is run…… Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark 35 Please enter the first mark : 35
13
Code Narrative Memory Screen 80 60 40 35 DIST MERIT PASS Mark
If the code has reached this else and not found that the mark entered is a distinction, merit or pass then it must be a fail. The text in quotes is printed to the console. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark 35 Please enter the first mark : 35 Fail
14
Code Narrative Memory Screen 80 60 40 35 DIST MERIT PASS Mark
The nested if statements end here. . Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark 35 Please enter the first mark : 35 Fail
15
Code Narrative Memory Screen 80 60 40 35 DIST MERIT PASS Mark
The prompt for the next grade is displayed. . Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If Console.Write("Please enter the next mark :") End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark 35 Please enter the first mark : 35 Fail Please enter the next mark :
16
Code Narrative Memory Screen 80 60 40 -1 DIST MERIT PASS Mark
The user enters the next mark and it is stored in the memory variable mark. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If Console.Write("Please enter the next mark :") End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark -1 Please enter the first mark : 35 Fail Please enter the next mark : -1
17
Code Narrative Memory Screen 80 60 40 -1 DIST MERIT PASS Mark
This is the end of the while loop ….but the program loops back the question at the head of the loop to check the value in the memory variable Mark to decide when to finish looping. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If Console.Write("Please enter the next mark :") End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark -1 Please enter the first mark : 35 Fail Please enter the next mark : -1
18
Code Narrative Memory Screen 80 60 40 -1 DIST MERIT PASS Mark
The loop will continue while the value in the memory variable Mark is greater than or equal to 0. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If Console.Write("Please enter the next mark :") End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark -1 Please enter the first mark : 35 Fail Please enter the next mark : -1
19
Code Narrative Memory Screen 80 60 40 -1 DIST MERIT PASS Mark
The loop will continue while the value in the memory variable Mark is greater than or equal to the value in Mark is less than 0 so the loop ends. Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If Console.Write("Please enter the next mark :") End While Console.ReadKey() End Sub Code Narrative Memory Screen DIST 80 MERIT PASS 60 40 Mark -1 Please enter the first mark : 35 Fail Please enter the next mark : -1
20
Narrative Memory 80 60 40 -1 Screen Code DIST MERIT PASS Mark
This line waits for the user to press a key before ending the program. DIST MERIT PASS Mark 80 60 40 -1 Screen Code Sub Main() 'This program demonstrates the use of IF…THEN…Else Const DIST = 80 Const MERIT = 60 Const PASS = 40 'Variables Dim Mark As Integer Console.Clear() Console.Write("Please enter the first mark :") Mark = Console.ReadLine() While Mark >= 0 If Mark >= DIST Then Console.WriteLine("Distinction") ElseIf Mark >= MERIT And Mark < DIST Then Console.WriteLine("Merit") ElseIf Mark >= PASS And Mark < MERIT Then Console.WriteLine("Pass") Else Console.WriteLine("Fail") End If Console.Write("Please enter the next mark :") End While Console.ReadKey() End Sub Please enter the first mark : 35 Fail Please enter the next mark : -1
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.