Codes Bible Updated Version April 2021
Codes Bible Updated Version April 2021
Table of Contents
ADDING TWO NUMBERS .................................................................................................................................5
SHOP CART......................................................................................................................................................... 21
CLASS.................................................................................................................................................................... 25
PATTERN 1 .......................................................................................................................................................... 27
PATTERN 2 ......................................................................................................................................................... 28
PATTERN 3.......................................................................................................................................................... 29
PATTERN 4 ......................................................................................................................................................... 31
FACTORIAL ......................................................................................................................................................... 33
INHERITANCE .................................................................................................................................................... 34
STRUCTURE 1 ..................................................................................................................................................... 39
STRUCTURE 2 .................................................................................................................................................... 40
2
FILES AND LIST BOX ...................................................................................................................................... 45
MOON ................................................................................................................................................................... 47
EMPLOYEE DATABASE.................................................................................................................................. 51
PROGRESSIVE CLOCK.................................................................................................................................... 56
PALINDROME .................................................................................................................................................... 71
SORT TEMPERATURE..................................................................................................................................... 75
ENABLED/DISABLED...................................................................................................................................... 76
FACTORS ............................................................................................................................................................. 80
LIBRARY DATABASE....................................................................................................................................... 86
AMSTRONG NUMBER..................................................................................................................................... 90
3
STRUCTURE WITH FUNCTIONS................................................................................................................. 98
4
ADDING TWO NUMBERS
Module Module1
Sub Main()
Dim num1 As Integer
Dim num2 As Integer
Dim answer As Integer
Console.WriteLine("Enter the first number :")
num1 = Console.ReadLine()
Console.WriteLine("Enter the second number :")
num2 = Console.ReadLine()
answer = num1 + num2
Console.WriteLine("{0} + {1} = {2}", num1, num2, answer)
Console.ReadKey()
End Sub
End Module
5
FINANCIAL PROBLEM 1
Nenyasha works as a part time assistant in a book shop and receives an hourly wage. Enter the number
of hours he worked for a specific week, as well as the pay rate per hour. He has to pay $8 per week
towards the recreation club. Write a console application to calculate and display how much he has
earned for the week.
Module Module1
Sub Main()
Dim hourly_wage As Integer
Dim hours As Integer
Dim result As Integer
Console.WriteLine("Enter hours worked")
hours = Console.ReadLine()
Console.WriteLine("Enter pay rate")
hourly_wage = Console.ReadLine()
result = hourly_wage * hours
Console.WriteLine(" earning for a week is ${0}", result - 8)
Console.ReadKey()
End Sub
End Module
6
FINANCIAL PROBLEM 2
Jane is a typist who works freelance and she charges the following rates:
A page typed single spacing $4.75
A page typed double spacing $3.50
The user must enter the number of pages she typed in single spacing and the number of pages she
typed in double spacing. Calculate the amount due. She saves 15% of this amount to buy supplies.
Write a console application to display the net amount she earned for her work.
Module Module1
Sub Main()
Dim SingleSpacing As Integer
Dim DoubleSpacing As Integer
Dim Cost1 As Single
Dim Cost2 As Single
Dim FinalCost1 As Single
Dim FinalCost2 As Single
7
8
FINANCIAL PROBLEM 3
Everybody in the town Chitungwiza will go to the circus during the weekend. Write a console program
to determine the entrance fee to the circus as persons younger than 12 years or 60 years of age or
more, receive a 25% discount. The user must enter the normal entrance fee and their age in years only.
Display the actual entrance fee to be paid on the screen.
Module Module1
Sub Main()
Dim Age As Integer
Dim EntranceFee As Integer
Dim FinalAmount As Integer
Dim FinalAmount2 As Integer
Console.WriteLine("Enter entrance fee")
EntranceFee = Console.ReadLine()
Console.WriteLine("Enter Age")
Age = Console.ReadLine()
If Age < 12 Or Age >= 60 Then
FinalAmount = 0.25 * EntranceFee
FinalAmount2 = EntranceFee - FinalAmount
Console.WriteLine("Entrance fee is {0}", FinalAmount2)
Else : Console.WriteLine("Entrance fee is {0}", EntranceFee)
End If
Console.ReadKey()
End Sub
End Module
9
FINANCIAL PROBLEM 4
Enock has a gardening service where he and his workers get paid per hour worked as can been seen in the table
below. He also charges an additional $2.50 per hour for equipment used. Write a console program to enter the
hours worked as a real number, calculate and display the amount owed to him. Use a select case statement to
calculate the amount.
0 - 2 $20.00
Module Module1
Sub Main()
Dim Hours As Integer
Dim Equip As Single
Dim Wage As Single
Console.WriteLine("Enter hours worked")
Hours = Console.ReadLine()
Case Is > 6
Equip = 2.5 * Hours
10
Wage = 17.88 * Hours
Console.WriteLine("Amount is {0}", Wage + Equip)
End Select
Console.ReadKey()
11
MATHEMATICAL PROBLEM 1
Write a VB.NET console program to enter 8 integers between 5 and 48. Display the average of these
numbers.
Module Module1
Sub Main()
Dim I As Integer
Dim Num(8)
Dim Sum As Integer = 0
Dim Ave As Integer
Console.ReadKey()
End Sub
End Module
12
13
MATHEMATICAL PROBLEM2
Public Class Form1
End Sub
14
15
MATHEMATICAL PROBLEM3
Public Class Form1
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim MajorTest1, MajorTest2, ClassTest1, ClassTest2, ExamMark, max,
Total As Double
MajorTest1 = TextBox1.Text
MajorTest2 = TextBox4.Text
ClassTest1 = TextBox2.Text
ClassTest2 = TextBox5.Text
ExamMark = TextBox3.Text
MajorTest1 = MajorTest1 * 0.15
MajorTest2 = MajorTest2 * 0.2
max = Hmark(ClassTest1, ClassTest2)
max = max * 0.15
ExamMark *= 0.5
Total = MajorTest1 + MajorTest2 + max + ExamMark
If Total > 50 Then
Label7.Text = "The final mark of the student is " & Total & "%"
& vbNewLine & "The result is a Pass"
Else
Label7.Text = "The final mark of the student is " & Total & "%"
& vbNewLine & "The result is a Fail"
End If
End Sub
16
TextBox4.Text = ""
TextBox5.Text = ""
Label7.Text = ""
End Sub
End Class
17
ARRAY PROBLEM 1
Module Module1
Sub Main()
Dim max, index As Integer
Dim arr() = {4, 15, 38, 53, 8, 95, 129, 653, 45, 658, 12, 40, 0, 98,
74, 32, 9, 39, 25, 87}
max = arr(0)
For i = 0 To 19
If arr(i) > max Then
max = arr(i)
index = i
End If
Next
Console.WriteLine("The highest number is " & max & " Index is " &
index)
Console.ReadKey()
End Sub
End Module
18
DASH CIRCLE
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Windows.Forms
Circle.X = 35
Circle.Y = 40
Circle.Width = 200
Circle.Height = 200
e.Graphics.DrawEllipse(pen, Circle)
pen.Dispose()
End Sub
End Class
19
GENERATE RANDOM NUMBERS
Public Class Form1
For num = 0 To 49
x = random.Next(20, 200)
ListView1.Items.Add(x)
Numbers(num) = x
Next
Array.Sort(Numbers)
Label1.Text = "Highest number is" & Numbers(49)
End Sub
End Class
20
SHOP CART
Public Class Form1
Private item1, item2, item3, item4, item5, item6 As Decimal
Private shirt As Decimal = 12.0
Private trousers As Decimal = 25.0
Private shoe As Decimal = 55.0
Private socks As Decimal = 3.5
Private hat As Decimal = 5.0
Private suit As Decimal = 95.0
End Sub
21
Private Sub CheckBox6_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox6.CheckedChanged
item6 = suit
End Sub
End Sub
End Class
22
ONE OF THE INPUTS IS NOT A NUMBER
Public Class Form1
Private Number1 As Decimal
Private Number2 As Decimal
Private Answer As Decimal
End Sub
Catch
TextBox3.Text = "Error"
Label4.Text = "One of the inputs is not a number. Please try
again!"
End Try
End Sub
End Sub
23
24
CLASS
Module Module1
Class Box
Public Length As Integer
Public Height As Integer
Public Width As Integer
End Class
Sub Main()
Dim Box1 As Box = New Box()
Dim Box2 As Box = New Box()
Dim Volume As Integer
'Initialising values for Box1
Box1.Length = 6
Box1.Height = 8
Box1.Width = 12
'Initialising values for Box2
Box2.Length = 5
Box2.Height = 9
Box2.Width = 15
Volume = Box1.Length * Box1.Height * Box1.Width
Console.WriteLine("Volume for box1 Is {0}", Volume)
Volume = Box2.Length * Box2.Height * Box2.Width
Console.WriteLine("Volume for box2 Is {0}", Volume)
Console.ReadKey()
End Sub
End Module
25
A CLASS WITH MEMBER FUNCTIONS
Module Module1
Class Box
Public Length As Integer
Public Width As Integer
Public Height As Integer
Public Sub SetLength(ByVal Len As Integer)
Length = Len
End Sub
Public Sub SetWidth(ByVal Wid As Integer)
Width = Wid
End Sub
Public Sub SetHeight(ByVal Hei As Integer)
Height = Hei
End Sub
Public Function GetVolume() As Integer
Return (Length * Height * Width)
End Function
End Class
Sub Main()
Dim Box1 As Box = New Box()
Dim Box2 As Box = New Box()
Dim Volume As Integer
'Specifying Box1
Box1.SetLength(6)
Box1.SetWidth(20)
Box1.SetHeight(12)
'Specifying Box2
Box2.SetLength(30)
Box2.SetWidth(23)
Box2.SetHeight(90)
Volume = Box1.GetVolume()
Console.WriteLine("Volume for Box1 is {0}", Volume)
Volume = Box2.GetVolume()
Console.WriteLine("Volume for Box2 is {0}", Volume)
Console.ReadKey()
End Sub
26
PATTERN 1
Module Module1
Sub Main()
Dim i, j, n As Integer
n = 5
For i = 1 To n
For j = 1 To i
Console.Write(i)
Next
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module
27
PATTERN 2
Module Module1
Sub Main()
For a = 1 To 7
For b = 1 To 7
If a >= b Then
Console.Write(b)
ElseIf a <= b Then
Console.Write("*")
End If
Next
Console.WriteLine()
Next
Console.ReadKey()
End Sub
End Module
28
PATTERN 3
Module Module1
Sub Main()
Dim n = 2
Dim py = n
Dim px = n
For i = 1 To n
Console.Write(" ")
For j = 1 To n * 2 - 1
If j >= px And j <= py Then
Console.Write("*")
Else : Console.Write(" ")
End If
Next
px = px - 1
py = py + 1
Console.WriteLine(" ")
Console.WriteLine()
Next
n = 3
px = 1
py = n * 2 - 1
For i = 1 To n
For j = 1 To n * 2 - 1
If j >= px And j <= py Then
Console.Write("*")
Console.ReadKey()
End Sub
End Module
29
30
PATTERN 4
Module Module1
Sub Main()
Dim n = 7
Dim py = n
Dim px = n
For i = 1 To n
For j = 1 To n * 2 - 1
If j >= px And j <= py Then
Console.Write("*")
Else : Console.Write(" ")
End If
Next
px = px - 1
py = py + 1
Console.WriteLine()
Next
n = 7
px = 1
py = n * 2 - 1
For i = 1 To n
For j = 1 To n * 2 - 1
If j >= px And j <= py Then
Console.Write("*")
Console.ReadKey()
End Sub
End Module
31
32
FACTORIAL
Public Class Form1
Private Num1 As Decimal
Private Answer As Decimal
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Num1 = TextBox1.Text
Answer = Math.Sqrt(Num1)
MsgBox(Answer)
End Sub
End Sub
MsgBox(Answer)
End Sub
33
INHERITANCE
Module Module1
Class Shape
Protected Length As Integer
Protected Width As Integer
Public Sub SetLength(ByVal Len As Integer)
Length = Len
End Sub
Public Sub SetWidth(ByVal Wid As Integer)
Width = Wid
End Sub
End Class
'Derived Class
Class Rectangle : Inherits Shape
Public Function GetArea() As Integer
Return (Length * Width)
End Function
End Class
Sub Main()
Dim Rect As Rectangle = New Rectangle()
Rect.SetLength(10)
Rect.SetWidth(5)
Console.WriteLine("Area is {0} :", Rect.GetArea())
Console.ReadKey()
End Sub
End Module
34
WRITING AND READING TO A FILE
Imports System.IO
Module Module1
Sub Main()
Dim s As String
Using sw As StreamWriter = New StreamWriter("D:\names.txt")
Console.WriteLine("Write Somethiung Dude")
s = Console.ReadLine()
sw.WriteLine(s)
End Using
' Read and show each line from the file.
Dim line As String
Using sr As StreamReader = New StreamReader("D:\names.txt")
line = sr.ReadLine()
While (line <> Nothing)
Console.WriteLine(line)
line = sr.ReadLine()
End While
End Using
Console.ReadKey()
End Sub
End Module
35
LOGIN APPLICATION THAT AUTHENTICATE
USERS
End Sub
36
Dim c As String = ListBox2.FindString(TextBox2.Text)
ListBox2.SelectedIndex = c
If (TextBox1.Text = ListBox1.Text) And (TextBox2.Text =
ListBox2.Text) Then
MsgBox("Welcome", 0 + 64, "Welcome")
Else : MsgBox("access derived", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Login fails")
End If
End Sub
End Class
37
CONSOLE WITH COLORS
Module Module1
Sub main()
For i = 1 To 4
If i = 1 Then
Console.ForegroundColor = ConsoleColor.White
Console.BackgroundColor = ConsoleColor.Black
Console.WriteLine("I LOVE WORKING WITH COLORS")
ElseIf i = 2 Then
Console.ForegroundColor = ConsoleColor.Red
Console.BackgroundColor = ConsoleColor.Black
Console.WriteLine("I LOVE WORKING WITH COLORS")
ElseIf i = 3 Then
Console.ForegroundColor = ConsoleColor.Red
Console.BackgroundColor = ConsoleColor.White
Console.WriteLine("I LOVE WORKING WITH COLORS")
Else
Console.ForegroundColor = ConsoleColor.Yellow
Console.BackgroundColor = ConsoleColor.Black
Console.WriteLine("I LOVE WORKING WITH COLORS")
End If
Next
Console.ReadKey()
End Sub
End Module
38
STRUCTURE 1
Module Module1
Public Structure City
Public Name As String
Public Population As Integer
Public Diameter As Integer
Public Year As Integer
End Structure
Sub Main()
Dim C As City
Console.WriteLine("Enter City name")
C.Name = Console.ReadLine()
Console.WriteLine("Enter City Population")
C.Population = Console.ReadLine()
Console.WriteLine("Enter City Diameter")
C.Diameter = Console.ReadLine()
Console.WriteLine("Enter City Year")
C.Year = Console.ReadLine()
Console.WriteLine("{0} City had a population of {1} million people
and a diameter of {2}km in the year {3}", C.Name, C.Population, C.Diameter,
C.Year)
Console.ReadKey()
End Sub
End Module
39
STRUCTURE 2
Create an application that makes use of a user defined type to capture student details and display
them. The details to be captured are: Name, course, department, city, phone number.
Module Module1
Structure Student
Dim Name As String
Dim course As String
Dim department As String
Dim city As String
Dim phone_number As String
End Structure
Sub Main()
Dim S(3) As Student
For i = 0 To 2
Console.WriteLine("Student" & i + 1)
Console.WriteLine("Enter Student name")
S(i).Name = Console.ReadLine
Console.WriteLine("Enter Course")
S(i).course = Console.ReadLine
Console.WriteLine("Enter department")
S(i).department = Console.ReadLine
Console.WriteLine("Enter city")
S(i).city = Console.ReadLine
Console.WriteLine("Enter phone number")
S(i).phone_number = Console.ReadLine
Next
For i = 0 To 2
Console.WriteLine("Student" & i + 1)
Console.WriteLine("Student name " & S(i).Name)
Console.WriteLine("Course " & S(i).course)
Console.WriteLine("department " & S(i).department)
Console.WriteLine("city " & S(i).city)
40
Console.WriteLine("phone number " & S(i).phone_number)
Next
Console.ReadKey()
End Sub
End Module
41
COMPOUND INTEREST
End Sub
42
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
Comp = 3
End Sub
End Sub
43
44
FILES AND LIST BOX
Using VB.Net design and write code for an application to create the file sports.txt on any location of
the computer, with the following details: Football, Basketball, Golf and Volleyball. Display the content
of the file sports.txt in a Listbox.
Imports System.IO
Public Class Form1
45
46
MOON
Imports System.Drawing.Drawing2D
Public Class Form1
47
DELIVERY SERVICES
48
If chkInsurance.Checked = True Then
lblInsurance_Cost.Text = 0.11 * Val(lblBasic_Cost.Text)
End If
If chkPriority.Checked = True Then
lblPriority_Cost.Text = 0.15 * Val(lblBasic_Cost.Text)
End If
End Sub
Function SubTotal() As Decimal
lblSub_Total.Text = Basic_cost() + Val(lblInsurance_Cost.Text) +
Val(lblPriority_Cost.Text)
Return lblSub_Total.Text
End Function
Sub Display()
travelling_way()
Basic_cost()
Extra()
lblVat.Text = 0.14 * SubTotal()
txtTotalCost.Text = Val(lblVat.Text) + SubTotal()
End Sub
Display()
End Sub
End Sub
49
lblSub_Total.Text = ""
lblVat.Text = ""
rbtAir.Checked = False
rbtBoat.Checked = False
rbtRailway.Checked = False
rbtRoad.Checked = False
chkInsurance.Checked = False
chkPriority.Checked = False
txtWeight.Focus()
End Sub
50
EMPLOYEE DATABASE
51
Public Class Form1
End Sub
End Sub
End Class
52
53
QUADRATIC EQUATION
a = TextBox1.Text
b = TextBox2.Text
c = TextBox3.Text
det = (b ^ 2) - (4 * a * c)
If (b ^ 2) > (4 * a * c) Then
TextBox4.Text = "2"
root1 = (-b + Math.Sqrt(det)) / (2 * a)
root2 = (-b - Math.Sqrt(det)) / (2 * a)
TextBox5.Text = root1
TextBox6.Text = root2
ElseIf (b ^ 2) < (4 * a * c) Then
MsgBox("No roots found", 0 + 16, "Error Report")
End If
End Sub
54
End Sub
End Sub
End Class
55
PROGRESSIVE CLOCK
End Sub
End Sub
56
57
SIMPLE CALCULATOR
Public Class Form1
Private num1 As Integer
Private num2 As Integer
Private result As Integer
End Sub
58
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
59
ADVANCED CALCULATOR
'================================CALCULATOR CODE==========================================
End Sub
End Sub
End Sub
60
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button16.Click
If Label22.Text = "0" Then
Label22.Text = "4"
Else
Label22.Text = Label22.Text + "4"
End If
End Sub
End Sub
End Sub
61
End Sub
End Sub
62
Label22.Text = ""
operation = "*"
End Sub
secondvalue = Label22.Text
If operation = "+" Then
answer = firstvalue + secondvalue
Label22.Text = answer
Label20.Text = ""
ElseIf operation = "^" Then
answer = firstvalue ^ secondvalue
Label22.Text = answer
Label20.Text = ""
63
answer = firstvalue / secondvalue
Label22.Text = "0"
Label22.Text = answer
Label20.Text = ""
Else : MsgBox("Hazviite zvaurikuda kuita", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Error")
Label22.Text = "0"
Label20.Text = "0"
End If
64
ADDING MULTIPLE VALUES IN 0NE TEXTBOX
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Num As String() = TextBox1.Text.Split(" ")
Dim Total As Long
For Each item As String In Num
Total += CType(item, Long)
Next
MsgBox(Total)
End Sub
End Class
65
SCORE BOARD
a = a + 1
TextBox2.Text = a
If a > b Then
TextBox5.Text = Name1 + " lead!"
ElseIf a < b Then
TextBox5.Text = Name2 + " lead!"
End If
End Sub
b = b + 1
TextBox3.Text = b
If a > b Then
TextBox5.Text = Name1 + " lead!"
ElseIf a < b Then
TextBox5.Text = Name2 + " lead!"
End If
End Sub
66
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
c = c + 1
TextBox6.Text = c
If c > 2 Then
c = 1
TextBox6.Text = c
End If
End Sub
67
SEQUENTIAL SEARCH ALGORITHM
Module Module1
Function sequSearch(ByVal dataset() As Integer, ByVal target As Integer,
ByVal n As Integer) As Integer
Dim i As Integer
Dim pos As Integer = -1
Dim found As Boolean = False
For i = 0 To n - 1 And found <> True
If (target = dataset(i)) Then
pos = i
found = True
End If
Next
Return pos
End Function
Sub Main()
Dim arr() As Integer = New Integer() {3, 12, 32, 34, 45, 90, 4, 20,
52, 74}
Dim pos As Integer
Dim tar As Integer
Console.Write("Find:")
tar = Integer.Parse(Console.ReadLine())
pos = sequSearch(arr, tar, arr.Length)
If (pos <> -1) Then
Console.WriteLine("Found at {0}", pos)
End Module
68
RANDOM NUMBERS
End Sub
69
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
70
PALINDROME
Public Class Form1
Else
MsgBox("Is not a palindrome")
End If
End Sub
71
FILE ON A FORM
Dim s As String
Try
Using sw As StreamWriter = New StreamWriter(TextBox5.Text)
For Each s In Employee
sw.WriteLine(s)
Next s
End Using
MsgBox("Saved!", 1 + 64)
Catch
72
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
73
YOU HAVE SELECTED THE CHECKBOX
74
SORT TEMPERATURE
Module Module1
Sub Main()
Dim Temp() = {34, 21, 19, 33, 41, 49, 13, 9, 56, 30}
Dim i As Integer
Array.Sort(Temp)
Console.WriteLine("Temperature starting with the hotest city")
For Each i In Temp
Console.WriteLine(i)
Next
Console.ReadKey()
End Sub
End Module
75
ENABLED/DISABLED
76
77
AIR ZIMBABWE
Module Module1
Sub Main()
Dim kg As Integer
Dim cost As Decimal
Dim cost2 As Decimal
Dim FinalCost As Decimal
Console.WriteLine("Enter kgs")
kg = Console.ReadLine
If kg <= 30 Then
cost = kg * 2
Console.WriteLine("The Charge is " & cost)
ElseIf kg > 30 And kg <= 40 Then
cost = 30 * 2
cost2 = (kg - 31) * 3.5
FinalCost = cost + cost2
Console.WriteLine("The charge is " & FinalCost)
ElseIf kg > 40 And kg <= 50 Then
cost = (30 * 2) + (9 * 3.5)
78
cost2 = (kg - 41) * 5.5
FinalCost = cost + cost2
Console.WriteLine("The charge is " & FinalCost)
Else
Console.WriteLine("Please put your luggage on a cargo")
End If
Console.ReadKey()
End Sub
End Module
79
FACTORS
End Sub
End Class
80
TENANT DATABASE
End Sub
TbltenantsBindingSource.EndEdit()
TbltenantsTableAdapter.Update(TenantsDataSet.tbltenants)
TbltenantsBindingSource.AddNew()
End Sub
81
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
82
DAY TIME
ElseIf hour >= 0 And hour <= 5 And minute >= 0 And minute <= 59 Then
lblHour.Text = hour & ":" & minute
lblTime.Text = "Night"
83
lblColor.Text = "Black"
ElseIf hour >= 6 And hour <= 10 And minute >= 0 And minute <= 59
Then
lblHour.Text = hour & ":" & minute
lblTime.Text = "Morning"
lblColor.Text = "Yellow"
ElseIf hour >= 11 And hour <= 12 And minute >= 0 And minute <= 59
Then
lblHour.Text = hour & ":" & minute
lblTime.Text = "Lunch"
lblColor.Text = "Orange"
ElseIf hour >= 14 And hour <= 17 And minute >= 0 And minute <= 59
Then
lblHour.Text = hour & ":" & minute
lblTime.Text = "Afternoon"
lblColor.Text = "Light Blue"
ElseIf hour >= 18 And hour <= 20 And minute >= 0 And minute <= 59
Then
lblHour.Text = hour & ":" & minute
lblTime.Text = "Evening"
lblColor.Text = "Dark Blue"
Else
lblHour.Text = "Invalid Input"
lblTime.Text = "Invalid Input"
lblColor.Text = "Invalid Input"
End If
End Sub
End Class
84
85
LIBRARY DATABASE
Create a database in MS-Access, call it Library and put the following fields:
Write a program and link it to the database. Your interface should be like the one below.
End Sub
86
Catch
MsgBox("Not Saved")
End Try
End Sub
End Sub
87
88
FIBONACCI SERIES
Write a program that allows the user to enter a number into a text box. Your program should then
calculate and display the first n terms of the Fibonacci series. The terms are displayed in a list box
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim n As Integer
Dim a As Integer = 0
Dim b As Integer = 1
n = TextBox1.Text
For i As Integer = 0 To n - 1
Dim temp As Integer = a
a = b
b = temp + b
ListBox1.Items.Add(a)
Next
End Sub
End Class
89
AMSTRONG NUMBER
Module Module1
Sub Main()
Dim r As Integer
Dim number As Long = 0
Dim sum As Long = 0
Dim c, temp As Long
Console.WriteLine("Enter an Integer up to which you want to find
amstrong number")
number = Console.ReadLine()
Console.WriteLine("Following Amstrong number are found from 1 To
{0}", number)
For c = 1 To number Step 1
temp = c
While temp <> 0
r = temp Mod 10
sum = sum + r * r * r
temp = temp / 10
End While
If c = sum Then
Console.WriteLine(c)
sum = 0
End If
Next
Console.ReadKey()
End Sub
End Module
90
CREATING A FOLDER
Imports System.IO
Public Class Form1
End Sub
End If
End Sub
End Class
91
INHERITANCE TEST
92
Public Class Form1
Class Person
Public Name As String
Public Address As String
Public Sub Enroll()
MsgBox("True-Called from Person")
End Sub
End Class
Class Student : Inherits Person
Dim S As Person = New Person
Sub Enrol()
MsgBox("True-Called from Student")
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim S As Person = New Person
Dim S1 As Student = New Student
S.Enroll()
S1.Enrol()
End Sub
End Sub
End Class
93
FILL COMBO BOX
End Sub
End Sub
94
95
CAR RACING
Public Class Form1
End Sub
End Sub
End Class
96
TRY CATCH DIVISION BY ZERO
Module Module1
Sub Main()
Dim num1 As Integer
Dim num2 As Integer
Dim Answer As Decimal
num1 = InputBox("Input num1")
num2 = InputBox("Input num2")
Try
Answer = num1 / num2
MsgBox("Your answer is " & Answer)
Catch ex As Exception
MsgBox("You cannot divide by zero", 1 + 16, "Error")
End Try
End Sub
End Module
97
STRUCTURE WITH FUNCTIONS
98
Module Module1
Structure Customer
Dim Name As String
Dim Income As Integer
Dim Delivery_Zone As Integer
Public Function Delivery_Cost() As Decimal
Dim Cost As Decimal
If Delivery_Zone = 1 Then
Cost = 10.0
ElseIf Delivery_Zone = 2 Then
Cost = 20.0
ElseIf Delivery_Zone = 3 Then
Cost = 30.0
ElseIf Delivery_Zone = 4 Then
Cost = 40.0
End If
Return Cost
End Function
End Structure
Sub Main()
Dim C(4) As Customer
For i = 0 To 4
Console.WriteLine("Customer {0}", i + 1)
Console.WriteLine("Enter customer name")
C(i).Name = Console.ReadLine()
Console.WriteLine("Enter Income")
C(i).Income = Console.ReadLine()
Console.WriteLine("Enter Delivery zone")
C(i).Delivery_Zone = Console.ReadLine()
Next
Console.WriteLine("Name" & vbTab & vbTab & "Income $" & vbTab &
"Zone" & vbTab & "Cost $")
For i = 0 To 4
Console.WriteLine(C(i).Name & vbTab & vbTab & C(i).Income &
vbTab & vbTab & C(i).Delivery_Zone & vbTab & C(i).Delivery_Cost())
Next
Console.ReadKey()
End Sub
End Module
99
100
PATTERN 2019
Module Module1
Sub Main()
For a = 0 To 5
For b = 0 To 5
If a Mod 2 = 0 Then
Console.Write(" * ")
Else
Console.Write(" *")
End If
Next
Console.WriteLine()
Next
Console.ReadKey()
End Sub
End Module
101
STOPWATCH
102
End Sub
End Class
103
DRAW PIE SHAPE
Imports System.Drawing.Drawing2D
Public Class Form1
End Class
104
MATRIX 3X3
Module Module1
Sub Main()
Dim matrix1(3, 3) As Integer
Dim matrix2(3, 3) As Integer
Product = 0
For k = 0 To 2
Product = Scalar * (matrix1(i, j))
Next
matrix2(i, j) = Product
Next
Next
Console.WriteLine("Matrix1: ")
For i = 0 To 2
For j = 0 To 2
105
Console.Write("{0} ", matrix1(i, j))
Next
Console.WriteLine()
Next
Console.WriteLine("Matrix2: ")
For i = 0 To 2
For j = 0 To 2
End Sub
End Module
106
UPPER CASE
End Class
107
108
FILES AND TEXTBOX
FileClose()
End Sub
End Class
109
SPIN BUTTON
End Sub
a = Random.Next(0, 9)
Label1.Text = a
b = Random.Next(0, 9)
Label2.Text = b
c = Random.Next(0, 9)
Label3.Text = c
End If
If a = 7 Then
PictureBox1.Visible = True
End If
If b = 7 Then
PictureBox1.Visible = True
End If
If c = 7 Then
PictureBox1.Visible = True
End If
110
End If
If DomainUpDown1.Text = "Random" Then
End If
End Sub
End Class
111
COPY, CUT & PASTE
End Sub
End Class
112
113
OPEN FILE DIALOG
Imports System.IO
Public Class Form1
114
SAVE FILE DIALOG
End Sub
End Class
115
VALIDATION
116
Public Class Form1
End Class
117
118
TANLEY INCOPERATED © 2021 ALL RIGHTS RESERVED
+263734246006
119