Professional Documents
Culture Documents
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
Answer:
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
i. Insert – It insert a line into control list above the selected line
iv. 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.
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.