[go: up one dir, main page]

100% found this document useful (2 votes)
2K views12 pages

VB Practical Exam Questions

This document contains 14 questions about writing Visual Basic .NET code. The questions cover topics like: - Accepting user input and displaying output - Error handling for invalid data types - Generating and displaying random numbers - Creating functions - Identifying and correcting errors in code The questions provide code snippets as examples and ask the reader to write VB.NET code to solve programming problems, displaying both the code and interface.

Uploaded by

Prosper Ndlovu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
2K views12 pages

VB Practical Exam Questions

This document contains 14 questions about writing Visual Basic .NET code. The questions cover topics like: - Accepting user input and displaying output - Error handling for invalid data types - Generating and displaying random numbers - Creating functions - Identifying and correcting errors in code The questions provide code snippets as examples and ask the reader to write VB.NET code to solve programming problems, displaying both the code and interface.

Uploaded by

Prosper Ndlovu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Vb.

Net PRACTICAL SAMPLE QUESTIONS


*all questions in this hand out are answered using visual basic dot net

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]

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

TextBox3.Text = TextBox1.Text + " " + TextBox2.Text

End Sub

End Class

Page 1 : Questions formulated and Answered by Pasi 0773 294 315


2) Write a programme that accepts two integer numbers and display the sum of those two
numbers. print code and interface [15]

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim a As Integer
Dim b As Integer
a = TextBox1.Text
b = TextBox2.Text
TextBox3.Text = a + b
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]

Page 2 : Questions formulated and Answered by Pasi 0773 294 315


Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim a As Integer

Dim b As Integer

Try

a = TextBox1.Text

b = TextBox2.Text

TextBox3.Text = a + b

Catch ex As Exception

MsgBox("you can only enter numbers")

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]

Page 3 : Questions formulated and Answered by Pasi 0773 294 315


Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim randomnumber As New Random
TextBox1.Text = randomnumber.Next

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]

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim randomnumber As New Random

Page 4 : Questions formulated and Answered by Pasi 0773 294 315


TextBox1.Text = randomnumber.Next(1, 10)

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”

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


MsgBox("Hello" + " " + TextBox1.Text)

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]
@
@@
@@@
@@@@
@@@@@

Page 5 : Questions formulated and Answered by Pasi 0773 294 315


(a)

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)

Page 6 : Questions formulated and Answered by Pasi 0773 294 315


Module Module1

Sub Main()

Dim row As Integer

Dim column As Integer

For row = 1 To 6

For column = 1 To 6

If row > column Then

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]

#####
#####
#####
#####
#####
#####
#####

Page 7 : Questions formulated and Answered by Pasi 0773 294 315


Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim column As Integer
Dim row As Integer
For row = 1 To 7
For column = 1 To 5
RichTextBox1.Text += " # "
Next
RichTextBox1.Text += Environment.NewLine()
Next
End Sub
End Class
9) Using different controls design a form that captures details of a secondary student to
enrolled for form one.

Page 8 : Questions formulated and Answered by Pasi 0773 294 315


CONTROLS USED
I. LABEL - chelstone high school
II. TEXTBOX --- name and surname input
III. GROUP BOX -- gender details
IV. RADIO BUTTONS --- male and female
V. COMBO BOX --- class
VI. DATE TIME PICKER --date of birth
VII. PICYUTR BOX --- picture
VIII. BUTTONS –cancel, enter and save record buttons
IX. RICH TEXT BOX – guardian /parent details
X. PANEL – green form boarders

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]

Page 9 : Questions formulated and Answered by Pasi 0773 294 315


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim word As String = TextBox1.Text
MsgBox(Len(word))
End Sub
End Class

11) Write a programme that converts a string to Upper case. Print code and interface [10]

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim word As String = TextBox1.Text
MsgBox("Your word in upper case is :" + UCase(word))
End Sub
End Class
12) Create a function in called “max” accepts two integer values and return the bigger of the
two numbers. Print code and interface [15].

Page 10 : Questions formulated and Answered by Pasi 0773 294 315


Private Function max(ByVal x As Integer, ByVal y As Integer) As Double ' max is the name of
the function, x and y are parameters

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]

Dim Number as integer


Dim Numberthree as integer
Dim Number two as integer
Dim Numberfour as integer
Numberthree =6
Num =1
Numbertwo = 9
Dim sum as string = Number + Numbertwo +Numberthree

Page 11 : Questions formulated and Answered by Pasi 0773 294 315


Textbox1.text = sum

(b) Suggest solutions to these errors

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)

Page 12 : Questions formulated and Answered by Pasi 0773 294 315

You might also like