ICT 10 - Lessons Finals

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1

Final Quarter Lessons in ICT 10



I. Data Input Controls:

1. OptionButton Control
it allows the user to select one category from a list of several Option Buttons created;
its most important property is the Value property which by default it is set to false;
however during run time, as you select an option button its value automatically changed to
True.

2. CheckBox Control
it operates like an option button except that it enables you to select multiple items or none
at all from the list;
if its Style property is set to 1-Graphical, the CheckBox Control will look like a
CommandButton control where you can add pictures to indicate checked and unchecked.

3. ListBox Control
it displays a list of fixed choices from which a user can select one or more items;
Vertical scroll bar is automatically displayed whenever the choices exceed the boundaries
of a ListBox control.

4. ComboBox Control
is almost similar to a ListBox control except that a ComboBox allows only a single response
from the user;
it takes up less space on a form because it shows only a single line of information;
its kinds are found in the Style property: 1-DropdownCombo, 2-SimpleCombo, and 3-
DropdownList.

PROJECTS/PROGRAMS: Food Menu/Menu Selector and Food Chain/Fast Food

II. File System Controls

1. DriveListBox Control
it lets you select the valid drives in your system at run time;
it displays a drop-down list of the current drive with its corresponding volume label;
its properties are almost identical to the ComboBox control except for some
items/properties;
its most significant property is its Drive property that contains the name of the drive as
well as the volume label of the drive; when a drive is selected, the control will only display
it and will not attempt to access it.

2. DirectoryListBox Control
it displays an ordered, hierarchical list of the directories and subdirectories of the current
drive;
its directory structure is displayed in a scrollable list box;
it is used to explore the directories of the current drive for saving and searching
documents;
its properties are almost the same as the ListBox Control
2

3. File List Box Control
it is used to locate the list of files in the current directory;
the current path directory is specified by its Path property;
its currently selected file is contained in its File Name property at run time
its most commonly fired event is the Click event. It will then contain codes as to what
action will be performed as a specific file is clicked

PROJECT/PROGRAM: Image Browser and Text File Viewer/Document Viewer
Steps:
1. Start MS Visual Basic and create a new project.
2. Place a DriveListBox Control (drvImageBrowswer), a DirectoryListBox Control (dirImageBrowser), a FileListBox Control
(filImageBrowser), a TextBox Control (txtImageBrowser) and an Image Control (imgImageBrowser) in the standard
form. Change the name of the objects using the Name Property accordingly.
3. Resize and place the objects appropriately on the form.
4. Set the Image controls stretch property to True so the image displayed will adjust to fit the control.
5. To limit the files to be displayed in the FileList Box to graphics files, change the value of its Pattern property by typing in
.bmp; .ico; .wmf; gif; .jpg. NOTE: each file extension is separated by a semicolon.
6. Double click an object in your form to display the Code Window and type the following statements:
Private Sub dirImageBrowser_Change()
filImageBrowser.Path = dirImageBrowser.Path
End Sub

Private Sub drvImageBrowser_Change()
dirImageBrowser.Path = drvImageBrowser.Drive
End Sub

Private Sub filImageBrowser_Click()
FileSelected = filImageBrowser.Path & "\" & filImageBrowser.FileName
imgImageBrowser.Picture = LoadPicture(FileSelected)
txtImageBrowser.Text = FileSelected
End Sub

7. Finally, run the program and you will notice that only graphics files are being displayed in the FileList Box.

NOTE:
1. The first two groups of codes update the current path of the directory and the file names as you change the
drive and the directory respectively.

2. The filImage Browser procedure contains the codes to display the image and the current path of the
selected file contained in the variable named FileSelected. The image is displayed as the LoadPicture()
function is called.

III. Special Type of Control

1. Timer Control
it executes at a regular interval and does not have a user interface that can be seen during
run time;
it only has one event, Timer, which reacts to the passage of time between certain intervals;
the execution of the Timer event can be controlled using Enable property;
If Enable is set to True, then the Timer event will be triggered; otherwise if set to False, the
execution of Timer event will be suspended.
The Timers Interval property is the Time (in milliseconds) in between call of Timer Event.


3

PROJECT/PROGRAM: Alarm Clock
Steps:
1. Start MS Visual Basic and create a new project.
2. Draw a ListBox control and name it as lstAlarms. This List Box lists the time when an alarm is activated.
3. Then draw another ListBox control named lstData. This List Box will contain the message to be posted when the alarm
is activated.
4. Add two commandbutton controls and name them as cmdAdd and cmdDelete. cmdAdd handles adding new alarms
while cmdDelete deletes the selected alarm from the list.
5. Add a Label control and name this lblTime. This will display the computer current time.
6. Draw a Timer control named tmrAlarm, set Enable property yo Trueand Interval property to 1000 since we only need to
update the label every 1 second or equivalent to 1000 milliseconds.
7. Label each item in the form accordingly.
8. Double click an object in your form to display the Code Window and type the following statements:

Private Sub cmdAdd_Click()
Dim strAlarm As String
Dim strTime As String
strAlarm = InputBox("Set new alarm " & vbCrL & "Enter Message to be displayed",
"Alarm Clock", "Message")
strTime = InputBox("What time should I post the important message?", "Alarm
Clock", "00:00 AM")
Do While IsDate(strTime) = False
strTime = InputBox("Please enter a valid time!", "Alarm Clock", "00:00 AM")
Loop
lstAlarms.AddItem (strTime)
lstAlarms.ItemData(lstAlarms.NewIndex) = 0
lstData.AddItem strAlarm, lstAlarms.NewIndex
End Sub

Private Sub cmdDelete_Click()
lstData.RemoveItem lstAlarms.ListIndex
lstAlarms.RemoveItem lstAlarms.ListIndex
End Sub

Private Sub lstAlarms_Click()
lstData.ListIndex = lstAlarms.ListIndex
MsgBox lstAlarms.ListIndex & lstAlarms.ListCount
End Sub

Private Sub tmrAlarm_Timer()
Dim i As Integer
For i = 0 To (lstAlarms.ListCount - 1)
If CDate(lstAlarms.List(i)) <= Time And lstAlarms.ItemData(i) = 0 Then
Beep
MsgBox lstData.List(i)
lstAlarms.ItemData(i) = 1
End If
Next
lblTime.Caption = Time

End Sub

9. Finally, run the program.


4

IV. Menus and Dialog Boxes
Aside from the controls provided by the Toolbox, Visual Basic also has another way of accessing
and displaying information in an application. As you have noticed, most Windows programs including
Visual Basic itself contain menus that add flexibility in displaying related commands in an organized
manner. Most applications come with a dialog box that indicates the status of your program as you
select a certain command.

1. Menu Editor
lets you add a menu bar containing various types of menus in your application;
it can be opened by choosing Tools Menu then Menu Editor or ; by pressing CTRL + E or by
clicking the Menu Editor button in the toolbar;
using the editor lets you set the properties of each menu item that will appear in your
application.

2. Creating a Menu
Each item in the menu is a Menu control that can be created using the Menu Editor.
The Menu control list box lists all the menu controls for the selected form. It also indicates
the relationship between menus.
o If the menu is not indented, it means that it is the menu title. Menu titles are the
menus that appear in the menu bar.
o If the item is indented once, then it is a submenu.
You cannot open the Menu Editor if you are in the Code Window.
You can create submenus up to five level deep.

PROJECTS/PROGRAMS: Menu Editor/Dialog Boxes/Formatting Menu
Steps:
1. Start MS Visual Basic and create a new project.
2. Select Form 1 then open the Menu Editor.
3. To create the File Menu, type &File on the caption text box. Just like in creating command button, an ampersand is
placed before the accessed key.
4. Type the desired name for this menu. For our example, type mnuFile. Please note that Name and Caption properties
are required.
5. Then to create the submenu under File menu, first click Next.
6. On the Caption text box, type &New and have mnuNew as its Name.
7. Click the right arrow button to indent the menu control indicating it is a submenu of the File menu we earlier created.
8. Then click Next or press the Enter key. You will notice that the new menu control to be created is already indented.
This means that when you create the next menu control, it will be automatically be a submenu of the File menu.
9. Create the submenus below by following steps 6 and 8.

Name Caption
mnuOpen &Open
mnuExit E&xit
mnuEdit &Edit
mnuCopy &Copy
mnuPaste &Paste
mnuDelete &Delete

10. As you noticed, mnuEdit becomes a submenu of the mnuFile. To make mnuedit a top level menu, first click the
.&Edit entry in the menu control list box. This will select mnuEdit. Click arrow left.
11. To close the Menu Editor, click OK.
12. Test the menu by selecting a menu during run time.

You might also like