Application Program Using Horizontal and Vertical Scroll Bars
Application Program Using Horizontal and Vertical Scroll Bars
Scrollbar
A vertical or horizontal bar commonly located on the far right or bottom of a window that allows you to move the
window viewing area up, down, left, or right. Most people today are familiar with scrollbars because of the need to
scroll up and down in almost every Internet web page. Below is an image of a Windows window with a vertical and
horizontal scrollbar.
Scrollbars are utilized using the mouse or keyboard. With a mouse, you can move scroll bar by clicking the scroll
arrow at either end of the scroll bars, click empty portions of the scroll bar, or click and drag the scroll box. With a
keyboard, you can use the up or down arrow keys, page up and page down key, and even the spacebar to move
the scrollbar. Most computers today also include a mouse with a wheel or button that allows you to scroll up and
A File control makes it easy to read, write, or append to a file in a file system. The files can be one of the
following types: Xml Object, Raw Data (binary), or String. When creating a File control, select the file type
that matches the files present in the specified directory.
In addition, the File control supports file manipulation operations such as copy, rename, and delete. You
can also retrieve a list of the files stored in the specified directory.
A File control performs an operation on a file. Each File control is customized to perform certain
operations.
This topic describes how to create a new File control and provides an example of the File control’s
declaration in the java file.
You can create a new File control and add it to your business process. To define a new File control:
1. In the Package Explorer pane, double-click the business process (Process.java file) to which you
want to add the File control. The business process is displayed in the Design view.
2. Click on the Data Palette and from the drop-down list choose Integration Controls to display
the list of controls used for integrating applications.
Note: If the Data Palette view is not visible in Oracle Workshop for WebLogic, click Window > Show
View > Data Palette from the menu bar.
3. Select File.
In the Field Name, type the variable name used to access the new File control instance
from your business process. The name you enter must be a valid Java identifier.
In the Insertion point: from the drop-down list select the point where you want the field
name to be inserted in the process file.
Decide whether you want to make this a control factory and select or clear the Make
this control factory that can create multiple instances at runtime check box.
Click Next.
Decide whether you want to add comments as configured in the properties of the
current project and select or clear the Generate comments check box.
Click Next.
In the Directory Name field, enter the name of the directory where the File control
looks for files. Alternatively, you can click the Browse button to locate a directory on your hard
disk.
A directory name is the absolute path name for the directory; it includes the drive specification
as well as the path specification. For example, the following are valid directory names:
C:\directory (Windows)
/directory (Unix)
You can also enter a period (.), which specifies the current working directory. When you enter
a forward slash (/) in the Directory Name field, it is interpreted as follows:
o Windows systems—the root of the user directory (for example, C: if the user
directory is C:\bea).
Note: When writing files locally, if the specified directory does not already exist, it is created and the file is
written into the new directory.
In the File name filter field, enter the file name filter, either a file name or file mask. Use
file names for read, write and append operations. If the file name field contains a wild-card character, such as an
asterisk (*), it is treated as a file mask. A wild-card character is specified to get the list of files in a directory. Wild-
card characters are not valid for any other operation.
The File name filter field is optional when inserting a control, but this property must then be set dynamically
before performing a file operation.
Select the type of data contained in the file using the Type of Data menu. The file type
indicates the type of files present in the directory specified in the Directory Name field. Based on this type,
appropriate methods (such as write (String data) or write(XmlObject data) or write(RawData data)) are generated
for the File control. For example, if the directory contains XML documents, the type should be set to XmlObject so
that read/write methods generated for the control will accept XmlObject variables. The same is true for RawData
and String types.
If you are operating on a file of type String or XmlObject, you can optionally specify the
character set encoding by entering the character set code in the Encoding field. This option cannot be used with
the large files option.
If the specified directory contains files you want to read one line at a time, select the
button labeled The directory contains large files to be processed. The resulting readLine()method is created with
support for large files.
You can define a line by specifying either its record size or a delimiter string:
o If you enter a record size in the Record Size field, the file is read that number of
bytes at a time.
o If you are operating on a file of type String and you enter characters in
the Delimiter string field, the file is read by record with each record defined as being terminated by that delimiter.
Click Read file content including delimiter string to include the delimiter in the record.
WARNING: If the specified delimiter string does not exist in a file being processed, application
behavior is unpredictable.
If no record size or string delimiter is specified, the file is processed one line at a time. A line
is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a
carriage return followed immediately by a linefeed. This style of file processing can be used
with any size file.
Note: You cannot define a line by specifying both a record size and a string delimiter.
Click Finish.
The drive list box is a drop-down list box. By default, the current drive is displayed on the user's system. When this
control has the focus, the user can type in any valid drive designation or click the arrow at the right of the drive list
box. When the user clicks the arrow, the list box drops down to list all valid drives. If the user selects a new drive
from the list, that drive appears at the top of the list box.
You can use code to examine the Drive property of the drive list box to determine which drive is currently selected.
Your application can also specify which drive appears at the top of the list box with this simple assignment:
Drive1.Drive = "c:\"
The drive list box displays valid available drives. Choosing a drive from the list box doesn't automatically change
the current working drive; however, you can use the Drive property to change drives at the operating system level
by specifying it as an argument to the ChDrive statement:
ChDrive Drive1.Drive
The File List Box
The file list box displays files contained in the directory specified by the Path property at run time. You can display
all the files in the current directory on the current drive using the following statement:
File1.Path = Dir1.Path
You can then display a subset of these files by setting the Pattern property — for example, *.frm displays only files
with that extension. The Pattern property can also accept a list delimited by semicolons. For example, a line with
the following code displays all files with the extensions .frm and .bas:
File1.Pattern = "*.frm; *.bas"
The directory list box displays the directory structure of the current drive on the user's system, beginning with the
top-level directory. Initially, the name of the current directory appears highlighted and indented from directories
above it in the hierarchy, back to the root. Subdirectories are indented beneath the current directory in the
directory list box. As a user moves up or down the list, each of the items is highlighted in turn.
Identifying Individual Directories
Each directory in the box has an integer identifier associated with it that allows you to identify individual
directories. This capability is not provided by the common dialog control. The directory specified by the Path
property (Dir1.Path) always has the ListIndex value of – 1. The directory immediately above it has the ListIndex
value of – 2, the one above that of – 3, and so on up to the root. The first subdirectory of Dir1.Path has the
ListIndex 0. If there are multiple directories at the first subdirectory level, the next has the ListIndex value of 1,
then 2, and so on, as shown in Figure 7.18.
Figure 7.18 A directory structure displayed in the directory list box
In order to manipulate data as described earlier you will need to understand some basic facts about how files can
be constructed. In particular, you'll need to know the following.
Data files stored as text files (a txt extension in DOS/Windows systems) are stored as a sequence of
characters.
Every character is stored as a single byte of data. You know that a byte can store a number from 0 to
255. Every character on the keyboard has a numerical representation.
There is a standard code for character representations. That code is the American Standard Code for
Information Interchange, that is ASCII, and that is pronounced "Ask-ee". When you strike a key on the
keyboard, the ASCII code for that key is what is transmitted to your computer.
Maybe the most important item on the list above is that every character is stored in a byte in a file. If you
have that concept, then you can compute how much information can be stored on a disk.
Let's just take a single megabyte (1MB). That's one million (1,000,000) bytes.
Disks can store more than that. Floppies can store 1.44 MB and hard drives can store many gigabytes (A
gigabyte is one billion bytes.)
If we can figure out how much you can get in a megabyte you can figure out how much you can get on a
floppy or a hard disk.
By that count, one megabyte could store 400 pages (2500 bytes/page x 400 pages = 1,000,000 bytes)
The particular book I was reading has only 267 pages, so the entire book could fit on a single floppy disk.
You can store a large amount of data even on a single floppy disk. Now, there are higher density disks
that hold 100 megabytes or 250 megabytes, so consider these problems.
C. Steps in Creating Program-Image Viewer
Introduction:
Welcome to a tutorial on how to create a Image Viewer in Visual Basic.
Steps of Creation:
Step 1:
First we want to create a form with a button to load the given image, a list box to contain each loadable image
from the given directory and a picture box with the background image format set to zoom to display the given
image correctly.
Step 2:
Next we want to create a defaultPath to load images from as well as load the image files on form load (open
program).
Dim default Path As String = "G:\Libaries\Pictures"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each foundFile As String In My.Computer.FileSystem.GetFiles(defaultPath)
If (foundFile.ToLower().EndsWith(".png") Or foundFile.ToLower().EndsWith(".ico") Or
foundFile.ToLower().EndsWith(".jpg") Or foundFile.ToLower().EndsWith(".jpeg") Or
foundFile.ToLower().EndsWith(".gif")) Then ListBox1.Items.Add(foundFile.Split("\")(foundFile.Split("\").Count() -
1))
Next
End Sub
Step 3:
Now we want to simply load the selected image file. We want to create an image variable with the default path
and selected image file from the listbox (file name and extension) and set the pictureboxes background image to
the created variable of image.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (Not ListBox1.SelectedIndex < 0) Then
Try
Dim img As Image = Image.FromFile(defaultPath & "\" & ListBox1.SelectedItem.ToString())
PictureBox1.BackgroundImage = img
Catch ex As Exception
End Try
End If
End Sub
Project Complete!
That's it! Below is the full source code and download to the project files.
Public Class Form1
Dim defaultPath As String = "G:\Libaries\Pictures"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each foundFile As String In My.Computer.FileSystem.GetFiles(defaultPath)
If (foundFile.ToLower().EndsWith(".png") Or foundFile.ToLower().EndsWith(".ico") Or
foundFile.ToLower().EndsWith(".jpg") Or foundFile.ToLower().EndsWith(".jpeg") Or
foundFile.ToLower().EndsWith(".gif")) Then ListBox1.Items.Add(foundFile.Split("\")(foundFile.Split("\").Count() -
1))
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (Not ListBox1.SelectedIndex < 0) Then
Try
Dim img As Image = Image.FromFile(defaultPath & "\" & ListBox1.SelectedItem.ToString())
PictureBox1.BackgroundImage = img
Catch ex As Exception
End Try
End If
End Sub
End Class
III. Designing Custom Menus
A. Menu Option
The File menu, shown below, will have the following level-two items below it: New, Open, Save, Save As, Print,
and Exit. Note that separator bars appear above the Save, Print, and Exit items.
The Help menu contains just one level-two item below it, About.
To build a menu for use with your VB program, you use the Menu Editor, which appears as an icon in the toolbar of
the VB IDE. It is the circled item in the screen shot below:
Alternatively, you can invoke the Menu Editor from the Tools menu item as shown below:
To build the menu described above, perform the following steps.
1. Start a new VB project and invoke the Menu Editor using either method shown above (click the Menu Editor
toolbar icon or select the Menu Editor option from the Tools menu). The Menu Editor screen appears, as
shown below:
2. For "Caption", type &File (by placing the ampersand to the left of the "F", we establish "F" as an access key for
the File item it enables the user to drop down the File menu by keying "Alt+F" on the keyboard in addition
to clicking the "File" item with the mouse).
For "Name", type mnuFile.
Your Menu Editor screen should look like this:
Click the Next button.
3. Click the "right-arrow" button (shown circled below). A ellipsis (...) will appear as the next item in the menu list,
indicating that this item is a level-two item (below "File").
For "Caption", type &New; for "Name", type mnuNew, and for "Shortcut", select Ctrl+N. By specifying a
shortcut, you allow the user to access the associated menu item by pressing that key combination. So
here, you are providing the user three ways of invoking the "New" function: (1) clicking File, then clicking
New on the menu; (2) keying Alt+F,N (because we set up an access key for "N" by placing an ampersand to
left of "N" in "New"); or (3) keying Ctrl+N. At this point, your Menu Editor screen should look like this:
Click the Next button.
4. For "Caption", type &Open; for "Name", type mnuOpen, and for "Shortcut", select Ctrl+O. Your Menu Editor
screen should look like this:
Click the Next button.
5. For "Caption", type - (a hyphen), and for "Name", type mnuFileBar1. A single hyphen as the Caption for a menu
item tells VB to create a separator bar at that location. Your Menu Editor screen should look like this:
Click the Next button.
6. For "Caption", type &Save; for "Name", type mnuSave, and for "Shortcut", select Ctrl+S. Your Menu Editor
screen should look like this:
Click the Next button.
7. For "Caption", type Save &As ..., and for "Name", type mnuSaveAs. Your Menu Editor screen should look like
this:
Click the Next button.
8. For "Caption", type -, and for "Name", type mnuFileBar2. Your Menu Editor screen should look like this:
Click the Next button.
9. For "Caption", type &Print;for "Name", type mnuPrint; and for "Shortcut", select Ctrl+P. Your Menu Editor
screen should look like this:
Click the Next button.
10. For "Caption", type -; and for "Name", type mnuFileBar3. Your Menu Editor screen should look like this:
Click the Next button.
11. For "Caption", type E&xit, and for "Name", type mnuExit. Your Menu Editor screen should look like this:
Click the Next button.
12. Click the "left-arrow" button (shown circled below). The ellipsis (...) no longer appears, meaning we are back to
the top-level items.
For "Caption", type &Help; and for "Name", type mnuHelp. Your Menu Editor screen should look like this:
Click the Next button.
13. Click the "right-arrow" button to create a level-two item below "Help". For "Caption", type &About; and for
"Name", type mnuAbout. Your Menu Editor screen should look like this:
14. At this point, we are done creating our menu entries, so click the OK button. That will dismiss the menu editor
and return focus to the VB IDE.
15. Back in the VB IDE, your form will now have a menu, based on what you have set up in the Menu Editor. If you
click on a top-level menu item (File for example), the level-two menu will drop down:
16. Click on the New menu item. The code window for the mnuFileNew_Click event opens, as shown below.
Note: Click is the only event that a menu item can respond to.
In thePlace mnuFileNew_Click event, place the code you want to execute when the user clicks the New menu
item. Since this is just a demo, we will place a simple MsgBox statement in the event procedure:
MsgBox "Code for 'New' goes here.", vbInformation, "Menu Demo"
17. Code similar MsgBox statements for the Open, Save, Save As, and Print menu items:
Private Sub mnuFileOpen_Click()
MsgBox "Code for 'Open' goes here.", vbInformation, "Menu Demo"
End Sub
Private Sub mnuFileSave_Click()
MsgBox "Code for 'Save' goes here.", vbInformation, "Menu Demo"
End Sub
Private Sub mnuFileSaveAs_Click()
MsgBox "Code for 'Save As' goes here.", vbInformation, "Menu Demo"
End Sub
Private Sub mnuFilePrint_Click()
MsgBox "Code for 'Print' goes here.", vbInformation, "Menu Demo"
End Sub
18. For the Exit menu item Click event, code the statement Unload Me.
Private Sub mnuFileExit_Click()
Unload Me
End Sub
19. For the About menu item Click event, code as shown below:
Private Sub mnuHelpAbout_Click()
MsgBox "Menu Demo" & vbCrLf _
& "Copyright " & Chr$(169) & " 2004 thevbprogrammer.com", , _
"About"
End Sub
20. Run the program. Note how the code executes when you click on the various menu items. Also test the use of
the access keys (e.g., Alt+F, N) and shortcut keys (e.g.,Ctrl-O).
21. Save the program and exit VB.
B. Shortcut
Here is a list of shortcut key combinations that can be using while developing applications in VB6
IDE Navigation
F2 Object Browser
F4 Property Window
Shift+F4 Property Pages
F6 Change Window (Split Window Mode)
F7 Code Window
Shift+F7 Object (Design) Window
Ctrl+D Add File
Ctrl+E Menu Editor
Ctrl+G Immediate Window
Ctrl+L Call Stack (When in RUN mode)
Ctrl+R Solutions Explorer
Ctrl+T Component Window
Ctrl+PgUp Go to Previous Sub/Function/Property (Declaration Line)
Ctrl+PgDn Go to Next Sub/Function/Property (Declaration Line)
Ctrl+Up Go to Previous Sub/Function/Property (First Line after Declaration)
Ctrl+Dn Go to Next Sub/Function/Property (First Line after Declaration)
Code Navigation
Shift+F2 Definition
Ctrl+Shift+F2 Last Cursor Position
F3 Find Next (Last searched item)
Shift+F3 Find Previous (Last searched item)
Ctrl+F3 Find Next (Current Selection)
Ctrl+Shift+F3 Find Previous (Current Selection)
Shift+F10 Context Menu (occasional erratic behaviour, use ContextMenuKey instead)
Form Designer
Shift+Arrow Resize Control
Ctrl+Arrow Move Control (Direction)
Ctrl+Space Complete Word
Ctrl+J List Properties/Methods
Ctrl+Shift+J List Constants
Ctrl+I Quick Info
Ctrl+Shift+I Parameter Info
Run
F5 Start/Continue
Ctrl+F5 Start with Full Compile
Ctrl+Break Break
Shift+F5 Restart
Debug
F8 Step Into
Shift+F8 Step Over
Ctrl+Shift+F8 Step Out
Ctrl+F8 Run To Cursor
Ctrl+W Edit Watch
Shift+F9 Quick Watch
F9 Add/Remove Breakpoint
Ctrl+Shift+F9 Clear All Breakpoints
Ctrl+F9 Set Next Statement
Ctrl+RightArrow Show End Variable Value (tooltip displying variable value is truncated,
use left arrow to view start again)
C.Pop up Menu
A pop-up menu is a floating menu that is displayed over a form, independent of the menu bar. The items displayed
on the pop-up menu depend on where the pointer was located when the right mouse button was pressed;
therefore, pop-up menus are also called context menus. In Microsoft Windows 95 or later systems, you activate
context menus by clicking the right mouse button.
Any menu that has at least one menu item can be displayed at run time as a pop-up menu. To display a pop-up
menu, use the PopupMenu method. This method uses the following syntax:
[object.]PopupMenu menuname [, flags [,x [, y [, boldcommand ]]]]
For example, the following code displays a menu named mnuFile when the user clicks a form with the right mouse
button. You can use the MouseUp or MouseDown event to detect when the user clicks the right mouse button,
although the standard is to use the MouseUp event:
Private Sub Form_MouseUp (Button As Integer, Shift As _
Integer, X As Single, Y As Single)
If Button = 2 Then ' Check if right mouse button
' was clicked.
PopupMenu mnuFile ' Display the File menu as a
' pop-up menu.
End If
End Sub
D. Standard Menu
Built-in menus appear on the menu bar across the top of the Visual Basic window. Each menu contains commands
that relate to the menu name. For example, the Format menu contains commands used for formatting your form.
Some of the commands have submenus that contains more specific commands. For example,
the Toolbars command on the View menu has a submenu that contains the names of the toolbars and
the Customize command. You can use the Customize command to modify the built-in menus or to add commands
to the menu bar.
You can use the Menu Editor to create new menus and menu bars, add new commands to existing menus, replace
existing menu commands with your own commands, and change and delete existing menus and menu bars.
To display the Menu Editor
From the Tools menu, choose Menu Editor.
–or–
Click the Menu Editor button on the toolbar.
This opens the Menu Editor, shown in Figure 6.7.
Figure 6.7 The Menu Editor
While most menu control properties can be set using the Menu Editor, all menu properties are available in the
Properties window. The two most important properties for menu controls are:
Name — This is the name you use to reference the menu control from code.
Other properties in the Menu Editor, including Index, Checked, and NegotiatePosition, are described later in this
chapter.
Using the List Box in the Menu Editor
The menu control list box (the lower portion of the Menu Editor) lists all the menu controls for the current form.
When you type a menu item in the Caption text box, that item also appears in the menu control list box. Selecting
an existing menu control from the list box allows you to edit the properties for that control.
For example, Figure 6.7 shows the menu controls for a File menu in a typical application. The position of the menu
control in the menu control list box determines whether the control is a menu title, menu item, submenu title, or
submenu item:
A menu control that appears flush left in the list box is displayed on the menu bar as a menu title.
A menu control that is indented once in the list box is displayed on the menu when the user clicks the
preceding menu title.
An indented menu control followed by menu controls that are further indented becomes a submenu title.
Menu controls indented below the submenu title become items of that submenu.
A menu control with a hyphen (-) as its Caption property setting appears as a separator bar. A separator
bar divides menu items into logical groups.
Note A menu control cannot be a separator bar if it is a menu title, has submenu items, is checked or disabled, or
has a shortcut key.
To create menu controls in the Menu Editor
–or–
Click the Menu Editor button on the toolbar.
3. In the Caption text box, type the text for the first menu title that you want to appear on the menu bar.
Also, place an ampersand (&) before the letter you want to be the access key for that menu item. This
letter will automatically be underlined in the menu.
The menu title text is displayed in the menu control list box.
4. In the Name text box, type the name that you will use to refer to the menu control in code. See "Menu
Title and Naming Guidelines" later in this chapter.
5. Click the left arrow or right arrow buttons to change the indentation level of the control.
6. Set other properties for the control, if you choose. You can do this in the Menu Editor or later, in the
Properties window.
–or–
Click Insert to add a menu control between existing controls.
You can also click the up arrow and down arrow buttons to move the control among the existing menu
controls.
8. Choose OK to close the Menu Editor when you have created all the menu controls for that form.
The menu titles you create are displayed on the form. At design time, click a menu title to drop down its
corresponding menu items.
Separating Menu Items
A separator bar is displayed as a horizontal line between items on a menu. On a menu with many items, you can
use a separator bar to divide items into logical groups. For example, the File menu in Visual Basic uses separator
bars to divide its menu items into three groups, as shown in Figure 6.8.
1. If you are adding a separator bar to an existing menu, choose Insert to insert a menu control between the
menu items you want to separate.
2. If necessary, click the right arrow button to indent the new menu item to the same level as the menu
items it will separate.
4. Set the Name property.
Note Although separator bars are created as menu controls, they do not respond to the Click event, and users
cannot choose them.
Assigning Access Keys and Shortcut Keys
You can improve keyboard access to menu commands by defining access keys and shortcut keys.
Access Keys
Access keys allow the user to open a menu by pressing the ALT key and typing a designated letter. Once a menu is
open, the user can choose a control by pressing the letter (the access key) assigned to it. For example, ALT+E might
open the Edit menu, and P might select the Paste menu item. An access-key assignment appears as an underlined
letter in the menu control's caption, as shown in Figure 6.9.
1. Select the menu item to which you want to assign an access key.
2. In the Caption box, type an ampersand (&) immediately in front of the letter you want to be the access
key.
For example, if the Edit menu shown in Figure 6.9 is open, the following Caption property
settings respond to the corresponding keys.
Cut Cu&t t
Copy C&opy o
&Paste p
Paste
De&lete l
Select &All a
Delete Time/&Date d
Select All
Time/Date
Note Do not use duplicate access keys on menus. If you use the same access key for more than one menu item,
the key will not work. For example, if C is the access key for both Cut and Copy, when you select the Edit menu and
press C, the Copy command will be selected, but the application will not carry out the command until the user
presses ENTER. The Cut command will not be selected at all.
Shortcut Keys
Shortcut keys run a menu item immediately when pressed. Frequently used menu items may be assigned a
keyboard shortcut, which provides a single-step method of keyboard access, rather than a three-step method of
pressing ALT, a menu title access character, and then a menu item access character. Shortcut key assignments
include function key and control key combinations, such as CTRL+F1 or CTRL+A. They appear on the menu to the
right of the corresponding menu item, as shown in Figure 6.10.
Figure 6.10 Shortcut keys
To remove a shortcut key assignment, choose "(none)" from the top of the list.
Note Shortcut keys appear automatically on the menu; therefore, you do not have to enter CTRL+key in the
Caption box of the Menu Editor.
Multimedia applications
Reflecting the generic, or buzzword, nature of the term multimedia is the range of applications that claim to be
multimedia. Existing and planned applications list such diverse target areas as electronic magazines, video--on-
demand, patient monitoring systems in hospitals, remote robotic agents, distance learning, and interactive
(WAN-)distributed virtual reality games. Using some rough categorizations we can sort multimedia applications
into the following categories (this list is not exhaustive):
Information systems: All systems whose main purpose is to provide information to a user (or a group of users).
Example application areas are :
hospital information systems: Patient monitoring systems, multimedia patient databases, mixed reality
surgery(e.g., virtual reality goggles)
navigation and information systems: shopping center /airport and other public spaces offer touch screen
multimedia orientation systems
museums:Online catalogs using high definition rendering of paintings, interactive online museum tours
(the Virtual Museum in Victoria or the Paris Louvre WebMuseum offer virtual reality museum trips ).
(Remote) representation: Systems which represent a user at a remote location. The representation can be
either passive or active---that is, the user can either just receive information about the remote location and the
actions taking place there (passive representation), or she can take part in the action and even influence the
process at the remote location (active representation). Notable example applications include:
conferencing applications: The user takes part in a conference; he/she can see and hear the other participants;
usually some kind of tool for showing text and graphics to the other participants is available.
distance learning: Distance learning is essentially the same as conferencing; instead of transmitting a conference
session or a group meeting, a seminar, a lecture, or a class is transmitted to students somewhere on the network.
remote robotic agents: The remote location might be situated inside a hazardous environment (e.g., the core of
a nuclear reactor, or a deep-sea exploration) which is too dangerous for the user as that she could be there in
person, yet, the task which the user wants to carry out requires human intervention.
remote task agents: Taking the concept of remote robotic agents one step further we can employ a piece of
software, an agent, to act on behalf of us: For example, the agent would travel across the Internet, visit a pre-
determined set of machines, carry out the instruction that we programmed it to do, bundle up the results (which,
of course, would be multimedia documents), and return to our workstation.
virtual reality:Whereas the conferencing and remote robotic agent applications represent the user at
another, existing, location, to which she could travel to instead, virtual reality applications represent users inside a
physically-nonexisting environment; for example, rather than accessing the records of a database through an
arcane retrieval language, the database user might enter a virtual reality representation of the database, which
would present individual records as old-fashioned folders.
Entertainment: This area attracts most of the attention of the general public as a lot of telecommunication and
media companies expect that the entertainment market will be the one with the largest audience and, also, the
market which is best suited for the employment of multimedia techniques. The following list presents just a short
excerpt of the projects planned and worked on:
digital television: Originally, digital television started out as a technology to deliver television broadcasts that
were to be of substantially higher quality and size than current, analog technology based broadcasting services
(the term high-definition television (HDTV ) was coined to describe these new broadcasting services). However, the
service providers that are implementing those services are already looking at other uses of the digital television
technology: Data transmission, paging systems, wireless telephony, and multiple television programs within one
channel are just a few of the uses in consideration, thereby pushing the original HDTV goal aside
interactive television: This kind of application is especially attractive for television companies and multimedia
"evangelists". The interactive part refers to the user's ability to partake in televised voting or game shows. The
attractive aspect of interactive television stems from the fact, that the necessary technological infrastructure is
already installed: Cable television and telephony services are available almost everywhere. Hence, startup-costs
are low; set-top boxes link the television set, the telephone, and the user .
Table 0 vbRSTypeTable
Dynaset 1 (Default) vbRSTypeDynaset
Snapshot 2 vbRSTypeSnapshot
The Recordset property returns the recordset object that provides the data being browsed in a form, report, list
box control, or combo box control. If a form is based on a query, for example, referring to the Recordset property
is the equivalent of cloning aRecordset object by using the same query. However, unlike using
the RecordsetClone property, changing which record is current in the recordset returned by the
form's Recordset property also sets the current record of the form.
This property is available only by using Visual Basic for Applications (VBA) code.
The read/write behavior of the Recordset property is determined by the type of recordset (ADO or DAO) and the
type of data (Access or SQL) contained in the recordset identified by the property.
Recordset type Based on SQL data Based on Access data
The following example opens a form, opens a recordset, and then binds the form to the recordset by setting the
form'sRecordset property to the newly created Recordset object.
Use the Recordset property:
To bind multiple forms to a common data set. This allows synchronization of multiple forms. For example,
To use methods with the Recordset object that aren't directly supported on forms. For example, you can
use theRecordset property with the ADO Find or DAO Find methods in a custom dialog for finding a record.
To wrap a transaction (which can be rolled back) around a set of edits that affect multiple forms.
Calling the Requery method of a form's recordset (for example, Forms(0).Recordset.Requery) can cause the form
to become unbound. To refresh the data in a form bound to a recordset, set the RecordSource property of the
form to itself (Forms(0).RecordSource = Forms(0).RecordSource).
When a form is bound to a recordset, an error occurs if you use the Filter by Form command.
Example
The following example uses the Recordset property to create a new copy of the Recordset object from the current
form and then prints the names of the fields in the Debug window.
Sub Print_Field_Names()
Dim rst As DAO.Recordset, intI As Integer
Dim fld As Field
Set rst = Me.Recordset
For Each fld in rst.Fields
' Print field names.
Debug.Print fld.Name
Next
End Sub
The next example uses the Recordset property and the Recordset object to synchronize a recordset with the form's
current record. When a company name is selected from a combo box, the FindFirst method is used to locate the
record for that company, causing the form to display the found record.
Sub SupplierID_AfterUpdate()
Dim rst As DAO.Recordset
Dim strSearchName As String
Set rst = Me.Recordset
strSearchName = CStr(Me!SupplierID)
rst.FindFirst "SupplierID = " & strSearchName
If rst.NoMatch Then
MsgBox "Record not found"
End If
rst.Close
End Sub
The following code helps to determine what type of recordset is returned by the Recordset property under
different conditions.
Sub CheckRSType()
Dim rs as Object
Set rs=Forms(0).Recordset
If TypeOf rs Is DAO.Recordset Then
MsgBox "DAO Recordset"
ElseIf TypeOf rs is ADODB.Recordset Then
MsgBox "ADO Recordset"
End If
End Sub
C. Data Manager
• At this point, we know how to use the data control and associated data bound tools to access a database. The
power of Visual Basic lies in its ability to manipulate records in code. Such tasks as determining the values of
particular fields, adding records, deleting records, and moving from record to record are easily done. This allows us
to build a complete database management system (DBMS).
• We don’t want to change the example database, BIBLIO.MDB. Let’s create our own database to change.
Fortunately, Visual Basic helps us out here. The Visual Data Manager is a Visual Basic Add-In that allows the
creation and management of databases. It is simple to use and can create a database compatible with the
Microsoft Jet (or Access) database engine.
• To examine an existing database using the Data Manager, follow these steps:
1. Select Visual Data Manager from Visual Basic’s Add-In menu (you may be asked if you want to
add SYSTEM.MDA to the .INI file - answer No.)
2. Select Open Database from the Data Manager File menu.
Once the database is opened, you can do many things. You can simply look through the various tables. You can
search for particular records. You can apply SQL queries. You can add/delete records. The Data Manager is a DBMS
in itself. You might try using the Data Manager to look through the BIBLIO.MDB example database.
1. Select Visual Data Manager from Visual Basic’s Add-In menu (you may be asked if you want to
add SYSTEM.MDA to the .INI file - answer No.)
2. Select New from the Data Manager File menu. Choose database type (Microsoft Access, Version
7.0), then select a directory and enter a name for your database file. Click OK.
3. The Database window will open. Right click the window and select New Table. In the Name box,
enter the name of your table. Then define the table’s fields, one at a time, by clicking Add Field, then
entering a field name, selecting a data type, and specifying the size of the field, if required. Once the field
is defined, click the OK button to add it to the field box. Once all fields are defined, click the Build the
Table button to save your table.
D. Ado Control
The ADO Data control uses Microsoft ActiveX Data Objects (ADO) to quickly create connections between data-
bound controls and data providers. Data-bound controls are any controls that feature a Data Source property. Data
providers can be any source written to the OLE DB specification. You can also easily create your own data provider
using Visual Basic's class module.
Although you can use the ActiveX Data Objects directly in your applications, the ADO Data control has the
advantage of being a graphic control (with Back and Forward buttons) and an easy-to-use interface that allows you
to create database applications with a minimum of code.
Several of the controls found in Visual Basic's Toolbox can be data-bound, including the Check Box, Combo Box,
Image, Label, List Box, Picture Box, and Text Box controls. Additionally, Visual Basic includes several data-bound
ActiveX controls such as the Data Grid, Data Combo, Chart, and Data List controls. You can also create your own
data-bound ActiveX controls, or purchase controls from other vendors.
Previous versions of Visual Basic featured the intrinsic Data control and the Remote Data control (RDC) for data
access. Both controls are still included with Visual Basic for backward compatibility. However, because of the
flexibility of ADO, it's recommended that new database applications be created using the ADO Data Control.
For More Information A complete list of data-bound controls can be found in "Controls That Bind to the ADO
Data Control." To find out how to use the intrinsic Data control or the Remote Data control, see "Using the Data
Control" or "Using the Remote Data Control." For details about creating a data provider, see "Creating Data-Aware
Classes."
Possible Uses
Open a specified database table or define a set of records based on a Structured Query Language (SQL)
query or stored procedure or view of the tables in that database.
Pass data field values to data-bound controls, where you can display or change the values.
Add new records or update a database based on any changes you make to data displayed in the bound
controls.
To create a client, or front-end database application, add the ADO Data control to your forms just as you would
any other Visual Basic control. You can have as many ADO Data controls on your form as you need. Be aware,
however, that the control is a comparatively "expensive" method of creating connections, using at least two
connections for the first control, and one more for each subsequent control.
Creating a Front-end Database Application with Minimal Code
It's possible to create a database application using a minimum of code by setting a few properties at design time. If
you are using an OLE DB data source, the Microsoft Data Link Name (.UDL) must be created on your machine. See
"Creating the North wind OLE DB Data Link" for a step-by-step example.
To create a simple front-end database application
1. Draw an ADO Data Control on a form. (The icon's ToolTip is "ADODC.")
If the control is not available in the Toolbox, press CTRL+T to display the Components dialog box. In
the Components dialog, click Microsoft ADO Data Control.
2. On the Toolbox, click the ADO Data Control to select it. Then press F4 to display the Properties window.
4. If you have created a Microsoft Data Link file (.UDL), select Use OLE DB File and click Browse to find the
file on the computer. If you use a DSN, click Use ODBC Data Source Name and select a DSN from the box,
or click New to create one. If you wish to use create a connection string, select Use Connection String,
and then click Build, and use the Data Link Properties dialog box to create a connection string. After
creating the connection string, click OK. The Connection String property will be filled with a string like:
5. driver={SQL Server};server=bigsmile;uid=sa;pwd=pwd;database=pubs
6. In the Properties window, set the Record Source property to a SQL statement. For example,
9. In the Properties window, set the DataSource property for Text1 to the name of the ADO Data control
(ADODC1). This binds the text box to the ADO Data control.
10. In the Properties window, click DataField and a list of available fields will drop down. Click the name of
the field you want to display.
11. Repeat steps 6, 7, and 8 for each additional field you want to access.
12. Press F5 to run the application. You can use the four arrow buttons on the ADO Data control to move to
the beginning of the data, to the end of the data, or from record to record through the data.
Setting the ConnectionString, Source, DataSource, and DataField Programmatically
The code below shows how to set these four properties programmatically. Note that setting the DataSource
property requires the Set statement.
Private Sub Form_Load()
With ADODC1
.ConnectionString = "driver={SQL Server};" & _
"server=bigsmile;uid=sa;pwd=pwd;database=pubs"
.RecordSource = "Select * From Titles Where AuthorID = 7"
End With
Set Text1.DataSource = ADODC1
Text1.DataField = "Title"
End Sub
E. Steps in Creating Database Program using Ado Control
To overcome these limitations, we can use a much more powerful data control in Visual Basic, known as ADO
control. ADO stands for ActiveX data objects. As ADO is ActiveX-based, it can work in different platforms (different
computer systems) and different programming languages. Besides, it can access many different kinds of data such
as data displayed in the Internet browsers, email text and even graphics other than the usual relational and
non relational database information.To be able to use ADO data control, you need to insert it into the toolbox. To
do this, simply press Ctrl+T to open the components dialog box and select Microsoft ActiveX Data Control 6. After
this, you can proceed to build your ADO-based VB database applications.
The following example will illustrate how to build a relatively powerful database application using ADO data
control. First of all, name the new form as frmBookTitle and change its caption to Book Titles- ADO Application.
Secondly, insert the ADO data control and name it as adoBooks and change its caption to book. Next, insert the
necessary labels, text boxes and command buttons. The runtime interface of this program is shown in the diagram
below, it allows adding and deletion as well as updating and browsing of data.
The property settings of all the controls are listed as follow:
When the dialog box appear, select the Use Connection String's Option. Next, click build and at the Data Link
dialog box, double-Click the option labeled Microsoft Jet 3.51 OLE DB provider.
After that, click the Next button to select the file BIBLO.MDB. You can click on Text Connection to ensure proper
connection of the database file. Click OK to finish the connection.
Finally, click on the RecordSource property and set the command type to adCmd Table and Table name to Titles.
Now you are ready to use the database file.
Now, you need to write code for all the command buttons. After which, you can make the ADO control invisible.
For the Save button, the program codes are as follow:
Private Sub cmdSave_Click()
adoBooks.Recordset.Fields("Title") = txtTitle.Text
adoBooks.Recordset.Fields("Year Published") = txtPub.Text
adoBooks.Recordset.Fields("ISBN") = txtISBN.Text
adoBooks.Recordset.Fields("PubID") = txtPubID.Text
adoBooks.Recordset.Fields("Subject") = txtSubject.Text
adoBooks.Recordset.Update
End Sub
For the Add button, the program codes are as follow:
Private Sub cmdAdd_Click()
adoBooks.Recordset.AddNew
End Sub
For the Delete button, the program codes are as follow:
Private Sub cmdDelete_Click()
Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion
Confirmation")
If Confirm = vbYes Then
adoBooks.Recordset.Delete
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
End If
End Sub
For the Cancel button, the program codes are as follow:
Private Sub cmdCancel_Click()
txtTitle.Text = ""
txtPub.Text = ""
txtPubID.Text = ""
txtISBN.Text = ""
txtSubject.Text = ""
End Sub
For the Previous (<) button, the program codes are
Private Sub cmdPrev_Click()
SQL, 'Structured Query Language', is a programming language designed to manage data stored in relational
databases. SQL operates through simple, declarative statements. This keeps data accurate and secure, and helps
maintain the integrity of databases, regardless of size.
Commands
ALTER TABLE
AND
SELECT column_name(s)
FROM table_name
WHERE column_1 = value_1
AND column_2 = value_2;
AND is an operator that combines two conditions. Both conditions must be true for the row to be included in the
result set.
AS
AVG
SELECT AVG(column_name)
FROM table_name;
AVG() is an aggregate function that returns the average value for a numeric column.
BETWEEN
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value_1 AND value_2;
The BETWEEN operator is used to filter the result set within a certain range. The values can be numbers, text or
dates.
COUNT
SELECT COUNT(column_name)
FROM table_name;
COUNT() is a function that takes the name of a column as an argument and counts the number of rows where the
column is not NULL.
C. Table Basics
Tables are database objects that contain all the data in a database. A table definition is a collection of columns. In
tables, data is organized in a row-and-column format similar to a spreadsheet. Each row represents a unique
record, and each column represents a field within the record. For example, a table that contains employee data for
a company can contain a row for each employee and columns representing employee information such as
employee number, name, address, job title, and home telephone number.
Tables in SQL Server have the following main components:
Columns
Each column represents some attribute of the object modeled by the table, such as a parts table having
columns for ID, color, and weight.
Rows
Each row represents an individual occurrence of the object modeled by the table. For example, the parts
table would have one row for each part carried by the company.
The following illustration shows the HumanResources.Department table in the AdventureWorks2008R2 sample
database.
Users work with the data in tables using data manipulation language (DML) Transact-SQL statements, as shown in
the following examples.
USE AdventureWorks2008R2;
GO
-- Get a list of all employees named Smith.
SELECT p.FirstName, p.LastName
FROM HumanResources.Employee e JOIN Person.Person p ON
e.BusinessEntityID = p.BusinessEntityID
WHERE p.LastName = 'Smith';
GO
-- Delete a purchase order detail record.
DELETE Purchasing.PurchaseOrderDetail
WHERE PurchaseOrderDetailID = 732;
D. Selection Data
The select statement is used to query the database and retrieve selected data that match the criteria that you
specify. Here is the format of a simple select statement:
select "column1"
[,"column2",etc]
from "tablename"
[where "condition"];
[] = optional
The column names that follow the select keyword determine which columns will be returned in the results. You
can select as many column names that you'd like, or you can use a "*" to select all columns.
The table name that follows the keyword from specifies the table that will be queried to retrieve the desired
results.
The where clause (optional) specifies which data values or rows will be returned or displayed, based on the criteria
described after the keyword where.
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal to
LIKE *See note below
The LIKE pattern matching operator can also be used in the conditional selection of the where clause. Like is a very
powerful operator that allows you to select only rows that are "like" what you specify. The percent sign "%" can be
used as a wild card to match any possible character that might appear before or after the characters specified. For
example:
This SQL statement will match any first names that start with 'Er'. Strings must be in single quotes.
This will only select rows where the first name equals 'Eric' exactly.
Enter the following sample select statements in the SQL Interpreter Form at the bottom of this page. Before you
press "submit", write down your expected results. Press "submit", and compare the results.
CREATE TABLE is the keyword telling the database system what you want to do. In this case, you want to create a
new table. The unique name or identifier for the table follows the CREATE TABLE statement.
Then in brackets comes the list defining each column in the table and what sort of data type it is. The syntax
becomes clearer with an example below.
A copy of an existing table can be created using a combination of the CREATE TABLE statement and the SELECT
statement. You can check complete details atCreate Table Using another Table.
Example:
Following is an example, which creates a CUSTOMERS table with ID as primary key and NOT NULL are the
constraints showing that these fields can not be NULL while creating records in this table:
SQL> CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25) ,
SALARY DECIMAL (18, 2),
PRIMARY KEY (ID)
);
You can verify if your table has been created successfully by looking at the message displayed by the SQL server,
otherwise you can use DESC command as follows:
SQL> DESC CUSTOMERS;
+---------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ID | int(11) | NO | PRI | | |
| NAME | varchar(20) | NO | | | |
| AGE | int(11) | NO | | | |
| ADDRESS | char(25) | YES | | NULL | |
| SALARY | decimal(18,2) | YES | | NULL | |
+---------+---------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
To insert records into a table, enter the key words insert into followed by the table name, followed by an open
parenthesis, followed by a list of column names separated by commas, followed by a closing parenthesis, followed
by the keyword values, followed by the list of values enclosed in parenthesis. The values that you enter will be held
in the rows and they will match up with the column names that you specify. Strings should be enclosed in single
quotes, and numbers should not.
In the example below, the column name first will match up with the value 'Luke', and the column name state will
match up with the value 'Georgia'.
Example:
C. Updating Records
The update statement is used to update or change records that match a specified criteria. This is accomplished by
carefully constructing a where clause.
update "tablename"
set "columnname" =
"newvalue"
[,"nextcolumn" =
"newvalue2"...]
where "columnname"
OPERATOR "value"
[and|or "column"
OPERATOR "value"];
[] = optional
Examples:
update phone_book
set area_code = 623
where prefix = 979;
update phone_book
set last_name = 'Smith', prefix=555, suffix=9292
where last_name = 'Jones';
update employee
set age = age+1
where first_name='Mary' and last_name='Williams';
D. Deleting Records
where "columnname"
OPERATOR "value"
[and|or "column"
OPERATOR "value"];
[ ] = optional
Examples:
Note: if you leave off the where clause, all records will be deleted!
To delete an entire record/row from a table, enter "delete from" followed by the table name, followed by the
whereclause which contains the conditions to delete. If you leave off the where clause, all records will be deleted.
C. Drop a Table
The drop table command is used to delete a table and all rows in the table.
To delete an entire table including all of its rows, issue the drop table command followed by the tablename. drop
tableis different from deleting all of the records in the table. Deleting all of the records in the table leaves the table
including column and constraint information. Dropping the table removes the table definition as well as all of its
rows.
Example:
The create table statement is used to create a new table. Here is the format of a simple create table statement:
Note: You may have as many columns as you'd like, and the constraints are optional.
Example:
To create a new table, enter the keywords create table followed by the table name, followed by an open
parenthesis, followed by the first column name, followed by the data type for that column, followed by any
optional constraints, and followed by a closing parenthesis. It is important to make sure you use an open
parenthesis before the beginning table, and a closing parenthesis after the end of the last column definition. Make
sure you seperate each column definition with a comma. All SQL statements should end with a ";".
The table and column names must start with a letter and can be followed by letters, numbers, or underscores - not
to exceed a total of 30 characters in length. Do not use any SQL reserved keywords as names for tables or column
names (such as "select", "create", "insert", etc).
Data types specify what the type of data can be for that particular column. If a column called "Last_Name", is to be
used to hold names, then that particular column should have a "varchar" (variable-length character) data type.
char(size) Fixed-length character string. Size is specified in parenthesis. Max 255 bytes.
varchar(size) Variable-length character string. Max size is specified in parenthesis.
number(size) Number value with a max number of column digits specified in parenthesis.
Date Date value
Number value with a maximum number of digits of "size" total, with a maximum number of "d"
number(size,d)
digits to the right of the decimal.
What are constraints? When tables are created, it is common for one or more columns to
have constraints associated with them. A constraint is basically a rule associated with a column that the data
entered into that column must follow. For example, a "unique" constraint specifies that no two records can have
the same value in a particular column. They must all be unique. The other two most popular constraints are "not
null" which specifies that a column can't be left blank, and "primary key". A "primary key" constraint defines a
unique identification of each record (or row) in a table. All of these and more will be covered in the future
Advanced release of this Tutorial. Constraints can be entered in this SQL interpreter, however, they are not
supported in this Intro to SQL tutorial & interpreter. They will be covered and supported in the future release of
the Advanced SQL tutorial - that is, if "response" is good.
It's now time for you to design and create your own table. You will use this table throughout the rest of the
tutorial. If you decide to change or redesign the table, you can either drop it or recreate it or you can create a
completely different one. The SQL statement drop will be covered later.