INTERSCHOOL EXAM OF - VISUAL BASIC - Level: Senior 6 TERM: 1st Academic Year: 2014 Time: 3hours
INTERSCHOOL EXAM OF - VISUAL BASIC - Level: Senior 6 TERM: 1st Academic Year: 2014 Time: 3hours
INTERSCHOOL EXAM OF - VISUAL BASIC - Level: Senior 6 TERM: 1st Academic Year: 2014 Time: 3hours
LEVEL: SENIOR 6
TERM: 1st
TIME: 3HOURS
_____________________________________________________________________________
INSTRUCTIONS:
5marks
3. Give an example which uses path property. 5marks
4. Give at least two events of File List Box. 10marks
5. Given the interface that follow: 10marks
11. Which one of the following is the correct syntax to make a control called Pic1 visible?
a. Pic1.Visible = True
b. Visible.Pic1 = True
c. Pic1.Invisible = False
d. Pic1.Enabled = True
Note: Number of hours must be entered as well as the appropriate rate. Gross salary =
rate * hours. Net salary = gross salary - deductions.
2. Write a VB program that will respond to the user action from this form: /10marks
3.
Examine the above Menu Editor and answer the following questions
a) What are two most important properties of Menu Editor? Explain
i. Insert
ii. Next
iii. Delete
iv. Ok
v. Cancel
4. Present at least in three ways of how the Select case can be used. And give an
example for each way
5. Following the steps given to build the Visual Basic application, solve the problem of
displaying in a label the square root of the number supplied by a user. /10marks
1. Write a VB program that allows the user to input the starting and end values. The
program calculates and displays the sum of the numbers between these values. The output
must be displayed in 1. Picture Box
2. List Box
a. Drive List Box: The drive list box control allows a user to select a valid disk
drive at run-time. It displays the available drives in a drop-down combo box.
b. Directory List Box: The directory list box displays an ordered, hierarchical list
of the user's disk directories and subdirectories. The directory structure is
displayed in a list box.
c. File List Box: The file list box locates and lists files in the directory specified by
its Path property at run-time. You may select the types of files you want to
display in the file list box.
2. Give the role of the property Path which is used on Directory List Box and Directory List Box
6. What will be the output of this code if the user input 8. /5marks
Private Sub cmdStart_Click()
Dim x As Single, y As Single
x = Val(txtX.Text)
y = x^2 + 1
picResults.Cls
picResults.Print “x = ”, x
picResults.Print “y = ”, y
End Sub
Answer:
X=8
Y=65
The example below illustrates the use of Check boxes and Option buttons. To capture
the information entered by means of these controls, you must test the property:
Value. In a Check box, Value = 1 if box is checked and = 0 if not. In an Option
button, Value = True if selected and = False if not.
11.Which one of the following is the correct syntax to make a control called Pic1
visible?
a. Pic1.Visible = True
b. Visible.Pic1 = True
c. Pic1.Invisible = False
d. Pic1.Enabled = True
SECTION B: Attempt any three questions /30marks
Note: Number of hours must be entered as well as the appropriate rate. Gross salary
= rate * hours. Net salary = gross salary - deductions.
Answer:
Private Sub cmdCancel_Click()
Form_Load
End Sub
Private Sub cmdConfirm_Click()
Dim name As String
Dim hrs As Single, deduction As Single
Dim rate As Single, gross As Single, net As Single
name = txtEmpName.Text
hrs = Val(txtHrs.Text)
deduction = Val(txtAmount.Text)
If optRateA.Value = True Then
rate = 10
ElseIf optRateB.Value = True Then
rate = 12.5
ElseIf optRateC.Value = True Then
rate = 15
End If
gross = hrs * rate
net = gross - deduction
lblGross.Caption = Str(gross)
lblNet.Caption = Str(net)
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub Form_Load()
txtEmpName.Text = ""
txtHrs.Text = ""
txtAmount.Text = ""
lblGross.Caption = ""
lblNet.Caption = ""
optRateA.Value = False
optRateB.Value = False
optRateC.Value = False
End Sub
2. Write a vb program that will respond to the user action from this form: /10marks
Answer:
End If
End Sub
Private Sub chkItalic_Click()
If chkItalic.Value = 1 Then
txtDisplay.FontItalic = True
Else
txtDisplay.FontItalic = False
End If
End Sub
Private Sub chkUnderline_Click()
If chkUnderline.Value = 1 Then
txtDisplay.FontUnderline = True
Else
txtDisplay.FontUnderline = False
End If
End Sub
Private Sub mcdExit_Click()
End
End Sub
Private Sub opt12_Click()
txtDisplay.FontSize = 12
End Sub
Private Sub opt14_Click()
txtDisplay.FontSize = 14
End Sub
Private Sub opt24_Click()
txtDisplay.FontSize = 24
End Sub
Private Sub optBlue_Click()
txtDisplay.ForeColor = vbBlue
End Sub
Private Sub optGreen_Click()
txtDisplay.ForeColor = vbGreen
End Sub
Private Sub optRed_Click()
txtDisplay.ForeColor = vbRed
End Sub
Name – This is the name you use to reference the menu editor
Caption – This is a text which will appear on control menu or sub menus
vii. Insert – It insert a line into control list above the selected line
x. Ok – it is a button that closes the menu editor and makes all modification
done to the selected form
4. Present at least in three ways of how the Select case can be used. And give an
example for each way. /10marks
Answer:
Select...Case structure is an alternative to If...Then...ElseIf for selectively executing a
single block of statements from among multiple block of statements. Select...case is
more convenient to use than the If...Else...End If.
- The select case visual basic command takes the place of multiple nested if
statements and makes your VB code clean and much easier to follow by neatly
handling the conditional flow of your VBA programming code.
Select Case expression
Case value1
Block of one or more VB statements
Case value2
Block of one or more VB Statements
Case value3
.
.
Case Else
Block of one or more VB Statements
End Select
1 . Dim grade As String
Private Sub Compute_Click( )
grade=txtgrade.Text
Select Case grade
Case "A"
lblresult.Caption="High Distinction"
Case "A-"
lblresult.Caption="Distinction"
Case "B"
lblresult.Caption="Credit"
Case "C"
lblresult.Caption="Pass"
Case Else
lblresult.Caption="Fail"
End Select
End Sub
2. Dim mark As Single
Private Sub Compute_Click()
'Examination Marks
mark = txtmrk.Text
Select Case mark
Case Is >= 85
lblcomment.Caption = "Excellence"
Case Is >= 70
lblcomment.Caption = "Good"
Case Is >= 60
lblcomment.Caption = "Above Average"
Case Is >= 50
lblcomment.Caption = "Average"
Case Else
lblcomment.Caption = "Need to work harder"
End Select
End Sub
5. Following the steps given to build a Visual Basic application, solve the problem of
displaying in a label the square root of the number supplied by a user.
/10marks
Answer:
Step 1 : Design the interface
1. Write a vb program that allows the user to input the starting and end values. The
program calculates and displays the sum of the numbers between these values.
Note: the start and end values are included. /15marks
Answer:
Private Sub cmdSum_Click()
Dim num1 As Single, num2 As Single, sum As Single
Dim i As Integer
sum = 0
picSum.Cls
listSum.clear
num1 = Val(txtNum1.Text)
num2 = Val(txtNum2.Text)
For i = num1 To num2
sum = sum + i
Next i
1. picSum.Print "The sum from "; num1; " to "; num2; " is "; sum
2. lstSum.AddItem sum
End Sub
2. Private Sub cmdDisplay_Click()
Dim num(25) as single
Dim sum as single, temp as single
Dim i as integer
pictorder.cls
lstvalue.clear
for i=1 to 25
num(i)=inputbox(“enter the value of number ”,i)
next i
rem displaying the values
for i=1 to 25
lstvalue.AddItem stud(i)
next i
rem ordering the numbers
for i=1 to 24
for i=i+1 to 25
if(num(i)>num(j)) then
temp=num(i)
num(i)=num(j)
num(j)-temp
end if
next j
next i
rem displaying ordered numbers
for i=1 to 25
picoorder.print num(i)
next i
rem calculation of the sum
sum= 0
for i=1 to 25
sum=sum + num(i)
next i
lblsum. Caption= “Their sum is” & sum
End sub
1.