1.
Use Table 1 to write a program to input mark attained by a student then output grade in
a given course unit using select case. Attach the code in a command button click event.
Figure 1: Command button click event with code.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
Private Sub btnProcess_Click(sender As Object, e As EventArgs) Handles
btnProcess.Click
Dim score As Integer
score = txtGrade.Text
Select Case score
Case 0 To 39
lblResult.Text = "E"
Case 40 To 49
lblResult.Text = "D"
Case 50 To 59
lblResult.Text = "C"
Case 60 To 69
lblResult.Text = "B"
Case 70 To 100
lblResult.Text = "A"
Case Else
lblResult.Text = "invalid score entered"
End Select
End Sub
End Class
2. Write a Visual Basic program to output the following series 1, 2 . . 99, 100 using Do
While...Loop.
Figure 2: Do While Loop Number Series
Public Class Form1
Private Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
Dim i As Integer = 1
Do While (i <= 100)
lstSeries.Items.Add(i)
i=i+1
Loop
End Sub
End Class
3. Using With … End With statement write a subprogram that will set Text1 properties as
follows; font size =14, bold, color = red, text= “ Hello World”
(4 marks)
Public Class MainForm
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
Private Sub SetTextProperties()
With Text1
.Text = "Hello World"
.FontSize = 14
.Font = New Font(.Font, FontStyle.Bold)
.ForeColor = Color.Red
End With
End Sub
End Class
4. Write a program code in Visual Basic using a CASE statement to output the type of
award of an employee given the number of years worked.
Module MainModule
Sub Main()
Dim yearsWorked As Integer
'Input the number of years worked
Console.Write("Enter the number of years worked: ")
yearsWorked = Integer.Parse(Console.ReadLine())
'Determine the type of award based on the number of years
worked
Dim awardType As String = GetAwardType(yearsWorked)
'Output the type of award
Console.WriteLine("Employee's Award Type: " & awardType)
Console.ReadLine()
End Sub
Function GetAwardType(yearsWorked As Integer) As String
Select Case yearsWorked
Case Is >= 15
Return "Gold"
Case Is >= 5
Return "Silver"
Case Is >= 2
Return "Bronze"
Case Is > 2
Return "None"
Case Else
Return "No Award"
End Select
End Function
End Module