VB Practical Exam Questions
VB Practical Exam Questions
1) Write a programme that accepts the first name and surname and then display the
full name of the person. Print code and interface. [10]
End Sub
End Class
3) Re write the question above so that if someone enters a letter in place of a number, an
error message will be displayed. Print code and interface [15]
Dim a As Integer
Dim b As Integer
Try
a = TextBox1.Text
b = TextBox2.Text
TextBox3.Text = a + b
Catch ex As Exception
End Try
End Sub
End Class
4) Write a programme that generates random numbers and display them in a text box. Print
code and interface [10]
End Sub
End Class
5) Write a programme that generates random numbers between 1 and 10 and then display
them in a text box. Print code and interface [15]
End Sub
End Class
6) Write a programme that prompts a user to enter his or her first name and display a
greeting message such as “Hello Sharlotte”
End Sub
End Class
7) (a) Write a programme to display the following pattern and print your output and code [10]
@@@@@@
@@@@@@
@@@@@@
@@@@@@
@@@@@@
@@@@@@
(b) Modify the code so that it prints the pattern as follows. [5]
@
@@
@@@
@@@@
@@@@@
Module Module1
Sub Main ()
Dim row As Integer
Dim column As Integer
For row = 1 To 6
For column = 1 To 6
Console.Write("@")
Next
Console.WriteLine()
Next
Console.Read()
End Sub
End Module
(b)
Sub Main()
For row = 1 To 6
For column = 1 To 6
Console.Write("@")
Else
Console.Write("")
End If
Next
Console.WriteLine()
Next
Console.Read()
End Sub
End Module
8) Write a programme that displays the harsh pattern below. Print your code and the form
interface [15]
#####
#####
#####
#####
#####
#####
#####
10) Write a programme to calculate the length of a string passed to it and display the length as
an integer number. Print code and interface. [15]
11) Write a programme that converts a string to Upper case. Print code and interface [10]
If x > y Then
Return x
Else
Return y
End If
End Function
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles
TextBox1.TextChanged
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As Integer = TextBox1.Text ' assigning textbox one text to a
Dim b As Integer = TextBox2.Text
Dim outcome As Double = max(a, b) ' passing a and b into the finction called max
declared above
MsgBox(outcome)
End Sub
End Class
13) (a) Identify errors in the following visual basic code meant to add three numbers and store
he result it in sum [8]
SOLUTION
(a) -“Number two” is not a Proper variable name. spacing is not allowed
- Num is an undeclared variable
- String data type on “sum” will make it impossible to store the numerical sum
- “Numberfour” is declared but not initialised
(b) -“Number two” should be written as “Numbertwo”
- Change” num” to “Number”
- Change data type on “sum” to integer or double
- Delete numberfour since it is not used in the programme.
14)