![Page 1: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/1.jpg)
WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC
BY
V. V. SUBRAHMANYAM
![Page 2: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/2.jpg)
Working with files
Visual Basic File System Controls
DriveList Box
DirList Box
FileList Box
![Page 3: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/3.jpg)
DriveList Box control
Is a drop down list box Displays the list of drives on your
computer The change is recorded in Drive
property of the DriveList Box
![Page 4: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/4.jpg)
DirList Box Control
It is a Drop down list box Displays the hierarchical list of
Directories in the current drive
![Page 5: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/5.jpg)
FileList Box
It is a Drop down list box Displays all files in the current directory
or folder and also allows the user to set up search criteria for files
![Page 6: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/6.jpg)
Advantages of file system controls
These three controls used together can create an elegant interface that will allow the user to locate a file on his computer
![Page 7: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/7.jpg)
![Page 8: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/8.jpg)
![Page 9: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/9.jpg)
![Page 10: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/10.jpg)
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Text1_Change()
File1.Pattern = Text1.Text
End Sub
![Page 11: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/11.jpg)
File functions ChDrive - Changes the current logged
drive ChDir - Changes the default
directory MkDir - Creates a new directory RmDir - Deletes a directory Name - Renames a file
![Page 12: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/12.jpg)
Contd…
Kill - Deletes a file FileCopy - Copies a file from src to des FileDateTime – Returns the date and
time when the file was modified GetAttr - Returns the attributes of a
file as an integer value SetAttr - Sets the attributes of a file
![Page 13: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/13.jpg)
Menus
Contains a no. of options, logically organized and easily accessible.
In VB Menus can be created using the Menu Editor
Menu is tied to a form.
![Page 14: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/14.jpg)
Menu Conventions
Keep menu captions short and simple Follow the Windows conventions while
naming and ordering the menu items Keep the list of menu items short Use separators to logically group menu
options Provide necessary keyboard shortcuts
![Page 15: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/15.jpg)
![Page 16: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/16.jpg)
![Page 17: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/17.jpg)
![Page 18: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/18.jpg)
![Page 19: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/19.jpg)
Multiple Document Interface (MDI) MDI was designed for applications
which need to show more than one document(multiple documents) at the same time, with each document displayed in its own window.
![Page 20: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/20.jpg)
Why MDI forms?
MDI form acts like a container for the other forms in the application
Most of the control buttons and code for the various forms can be shared
Reduces the no. of controls
![Page 21: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/21.jpg)
MDI Application
An application can have only one MDI form
One or more MDI Child Form(s) Optionally independent forms and
modules
![Page 22: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/22.jpg)
Data Base It is a collection of records stored in
tables. Information is stored in tabular form and
is called a table.
Columns Fields
Rows Records The collection of the tables is called as
database and are stored in a file.
![Page 23: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/23.jpg)
Three categories of databases
Visual Basic recognizes 3 categories of databases
Visual basic database
External databases
ODBC databases
![Page 24: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/24.jpg)
Creating a table
You can create your own tables using– DAO(Data Access Objects)– Microsoft Access and others– Visual Data Manager
![Page 25: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/25.jpg)
Visual Data Manager
Visual Data manager makes the job of table creation and modification very simple.
This can work with MS-Access, Dbase, Paradox and text files also.
![Page 26: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/26.jpg)
![Page 27: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/27.jpg)
Data Control
Establishes a connection to a database Returns a set of records from the
database Enables you to move from record to
record Enables you to display and manipulate
data from the records in bound controls
![Page 28: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/28.jpg)
Properties to be set to Data control Two properties to be set at runtime or
design time are:
DatabaseName: Specifies the name of the database that must be opened
RecordSource: Specifies the name of the table(s) of the database from which the data has to be extracted
![Page 29: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/29.jpg)
Data-Aware Control
It is the control that provides access to a specific field in a database through a data control.This can be bound to a data control through its data source and data field properties.
![Page 30: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/30.jpg)
DBlist, Dbcombo and Dbgrid
These controls are all capable of managing sets of records when bound to a Data Control. All of these controls permit several records to be displayed or to be manipulated at a time.
![Page 31: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/31.jpg)
`Object Linking and Embedding(OLE) To create an application that can
display data from many different applications and enables the user to edit that data from with in the application in which it was created.
![Page 32: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/32.jpg)
OLE DB It is defined as a new low-level interface
that is part of the Universal Data Access platform.
It is general purpose set of interfaces designed to let developers build data access tools as components using the COM.
![Page 33: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/33.jpg)
Additional Controls Sstab control Provides an easy way of presenting
several dialogs or screens of information on a single form, using the same interface seen in many commercial Windows applications.
![Page 34: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/34.jpg)
ImageList control
This control acts like a repository of images for the other controls
![Page 35: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/35.jpg)
MSFlexGrid control
This displays and operates on data in a table form
![Page 36: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/36.jpg)
Toolbar Control
This is used to create a toolbar for the application, just like Toolbars for applications like Word or Excel or others.
![Page 37: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/37.jpg)
Statusbar Control
This control holds up to a maximum of sixteen panels or frames each of these panel given different types of information like time, microhelp, status of a key etc..
![Page 38: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/38.jpg)
Treeview Control
To display the data as a hierarchy. It displays the drives, directories, subdirectories and files in the form of a hierarchy.
![Page 39: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/39.jpg)
ActiveX Data object
This enables the client applications to access and manipulate data in a database serer through any of the OLE DB providers.
![Page 40: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/40.jpg)
Benefits of ADO
Ease of use High speed Low memory overheads Small disk footprint
![Page 41: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/41.jpg)
ADO support
ADO support key features for building client/server and Web-based applications.
![Page 42: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/42.jpg)
BUG
The error or the problem occurred in the system is called as a bug
![Page 43: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/43.jpg)
Debugging
The process of finding out and removing the error is called debugging.
![Page 44: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/44.jpg)
Types of Bugs
Errors of syntax Logical errors Runtime Errors
![Page 45: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/45.jpg)
Debugging Methods
The Message box Debug.print Debug Toolbar Error Handler
![Page 46: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/46.jpg)
Message Box To display the state of values that have
been assigned to a variable
Dim I as integer
For I = 1 to 20 step 4
MsgBox I
-----
Next I
![Page 47: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/47.jpg)
Debug.print
The debug object will send the output to the immediate window.
Dim I as integer
For I = 1 to 20 Step 4
Debug.print I
Next I
![Page 48: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/48.jpg)
Debug Toolbar
To begin debugging, Debug Toolbar is required.
To bring up, right click the toolbar and select Debug from the pop-up menu
![Page 49: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/49.jpg)
![Page 50: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/50.jpg)
![Page 51: WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC](https://reader036.vdocument.in/reader036/viewer/2022062800/568142cc550346895daf2301/html5/thumbnails/51.jpg)
Error handler
It is a routine that traps errors and directs the user or the program to perform a certain task to overcome the error.