0% found this document useful (0 votes)
68 views4 pages

Event Driven Programming

Uploaded by

merrymutish03
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)
68 views4 pages

Event Driven Programming

Uploaded by

merrymutish03
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

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


[Link]

End Sub

Private Sub btnProcess_Click(sender As Object, e As EventArgs) Handles


[Link]
Dim score As Integer
score = [Link]
Select Case score
Case 0 To 39
[Link] = "E"
Case 40 To 49
[Link] = "D"
Case 50 To 59
[Link] = "C"
Case 60 To 69
[Link] = "B"
Case 70 To 100
[Link] = "A"
Case Else
[Link] = "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 [Link]
Dim i As Integer = 1

Do While (i <= 100)


[Link](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
[Link]
End Sub
Private Sub SetTextProperties()
With Text1
.Text = "Hello World"
.FontSize = 14
.Font = New Font(.Font, [Link])
.ForeColor = [Link]
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


[Link]("Enter the number of years worked: ")
yearsWorked = [Link]([Link]())

'Determine the type of award based on the number of years


worked
Dim awardType As String = GetAwardType(yearsWorked)
'Output the type of award
[Link]("Employee's Award Type: " & awardType)

[Link]()
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

You might also like