Visual Basic 6.0
Visual Basic is a highly popular language in the commercial world because it allows for the rapid development of Windows based programs. VB is particularly strong at creating front ends for databases. This can be done in amazing time through the use of wizards. This page does not cover all aspects of VB, it does not show how to do the basics like layout a form, neither does it cover all the built in functions, as there is already plenty of help provided for these, and a lot of it is self-evident.
A more limited version of Visual Basic is also included in several other Microsoft Applications such as MS Access. Most of the information here applies to that version.
VISUAL BASIC 6.0 is the developed version of BASIC (beginner all purpose symbol instruction code).
BASIC was developed in mid 1960 by John and Thomas Kurtz of Dartmouth college as language to create simple program. With the development of Microsoft windows graphical user interface BASIC was converted into VISUAL BASIC.
The VISUAL part refers a method used to create the graphical user interface rather than writing various lines of code. VISUAL BASIC is a high level language and its program created in integrated development environment (IDE). VISUAL BASIC developed in 1991 since 1991 to 1996 there was 6 versions developed VB 1.0, 2.0, 3.0, 4.0, 5.0 and last one is VB 6.0.
All these features provide us the facilities to develop an application. VB provide us the object oriented and event driven programming and a flexible format of application. It is based on Single Document Interface (SDI) and multiple Document Interface (MDI) . It gives us online interest facility for our project and it is a Graphical User Interface (GUI).
When using VISUAL BASIC, the most important skill you need is to be adept at using the development environment. Without the integrated tools in the environment, VISUAL BASIC programming would be much more cumbersome and difficult. All design would need to be done on graph paper and flow charts, and it would need to be typed line by line. Fortunately VISUAL BASIC contains many integrated tools to make the application development process simpler. This collection of tools makes up the Integrated Development Environment (IDE).
Visual Basic
Contents...
· Introduction
· History
· Visual Basic IDE
· Visual Basic Tools
· Data Types
· Constants
· Enumerations
· Types
· Arrays
· If-Then-Else
· While Structures
· For Structure
· Sub Procedures
· Function Procedures
· Property Procedures
· Modules
Introduction
Visual Basic is a highly popular language in the commercial world because it allows for the rapid development of Windows based programs. VB is particularly strong at creating front ends for databases. This can be done in amazing time through the use of wizards. This page does not cover all aspects of VB, it does not show how to do the basics like layout a form, neither does it cover all the built in functions, as there is already plenty of help provided for these, and a lot of it is self-evident.
A more limited version of Visual Basic is also included in several other Microsoft Applications such as MS Access. Most of the information here applies to that version.
History of VISUAL BASIC 6.0
VISUAL BASIC 6.0 is the developed version of BASIC (beginner all purpose symbol instruction code).
BASIC was developed in mid 1960 by John and Thomas Kurtz of Dartmouth college as language to create simple program. With the development of Microsoft windows graphical user interface BASIC was converted into VISUAL BASIC.
The VISUAL part refers a method used to create the graphical user interface rather than writing various lines of code. VISUAL BASIC is a high level language and its program created in integrated development environment (IDE). VISUAL BASIC developed in 1991 since 1991 to 1996 there was 6 versions developed VB 1.0, 2.0, 3.0, 4.0, 5.0 and last one is VB 6.0.
Features of VB 6.0
· Object Oriented Programming
· Event Driven Programming
· Flexible format of Windows application
· SDI and MDI
· Online Interest Facility
· Using GUI
All these features provide us the facilities to develop an application. VB provide us the object oriented and event driven programming and a flexible format of application. It is based on Single Document Interface (SDI) and multiple Document Interface (MDI) . It gives us online interest facility for our project and it is a Graphical User Interface (GUI).
Introduction of IDE
When using VISUAL BASIC, the most important skill you need is to be adept at using the development environment. Without the integrated tools in the environment, VISUAL BASIC programming would be much more cumbersome and difficult. All design would need to be done on graph paper and flow charts, and it would need to be typed line by line. Fortunately VISUAL BASIC contains many integrated tools to make the application development process simpler. This collection of tools makes up the Integrated Development Environment (IDE).
Introduction of VB Tools
VISUAL BASIC 6.0 contain different type of tools namely like: Menu bar, Tool bar, Tool box, Property window, Project Explorer, etc.
Some commonly used tools explain following:
Ø Label
Ø Textbox
Ø Image box
Ø Command button
Ø Frame
Ø Timer
LABELS:
This is a control used to write display text in design time. So it is used to give title and heading. It is non-editable at run-time. It has some properties like Name, Allignment, Appearance, Back color, Fore color, Caption,
Mouse pointer, Picture, Style, Font etc.
TEXT BOX:
Text box is commonly used to enter text at the design time or run-time. We use text property to enter information which we want to
display. It has some properties like: Multiline, scroll bar, max length, password character, locked etc.
IMAGE OBJECT:
The image control is a lightweight equivalent of the picture box control but unlike the picture control. In some of its other properties it’s not as versatile but it’s a good choice if you simply want to display a picture on form. It consume far less memory than picture control. It has some properties like: appearance, border style, index mouse pointer, picture, stretch etc.
COMMAND BUTTON:
This is the most common windows application control. It is used to execute or activate any operation. It has some properties like: cancel, caption, container, font, height, mouse icon, mouse pointer etc.
FRAME:
The frame is often used as a container for check box group and also for option button and other controls. It has some properties like: appearance, back color, fore color, container, caption, mouse pointer etc.
TIMER:
It is used to execute code at regular time interval of time. It provides the interval property with a time in milliseconds (1sec=1000 milisec). It is invisible at run-time. It has some property like: enabled, index, top, tag, parent, interval etc.
TOOL BOX
Data Types
- Byte : 1 Byte
- Integer : 4 Byte (on 32 bit) : %
- Long : 4 Bytes : &
- Single : 7 Digits : !
- Double : 16 Digits : #
- String
- Boolean (b As Boolean / b = true, false)
- Date (d As Date / d = #01/01/2000)
- Currency
- Variant
Constants
Constants are declared as follows:
Const name [As Type] = value
eg. Const i As Integer = 10
Enumerations
Enumerations are declared as follows:
Public Enum X
Value1
Value2
End Enum
dim e As X
e = Value1
Types (records)
Types are created along the lines of the following example:
Public Type Person
Name As String
Age As Integer
End Type
Dim mark As Person
mark.Name = "Mark"
Arrays
Fixed size arrays are created as follows:
Dim initarray(10) As Integer
this will create an array of 10 elements starting at 0
Alternatively you can state the starting number
Dim initarray(10 To 19) As Integer
Elements can then be used as follows:
initarray(0) = 10
Two dimensional arrays are created as follows:
twodimension(10, 10) As Integer
They are used as follows:
twodimension(0, 0) = 10
Arrays can also be made dynamic. The first step is to declare an array as follows:
expandable() As Integer
It can then be given 'x' number of elements as follows:
ReDim expandable(x)
To increase the array another time while keeping the current elements use the following structure:
Redim Preserve expandable(y)
If-Then-Else
The basic structure is as follows:
If condition1 Then
statements
Else If condition2 Then
statements
Else
statements
End If
The Else If portion is optional, as is the Else part.
The Case structure goes as follows:
Dim x As Integer
Select Case x
Case 0
statement
Case 1
statement
Case Else
statement
End Select
While Structures
There are two while structures. The main one is:
Do While condition
statements
Loop
This will not necessarily execute.
The other one, which will always execute once is:
Do
statements
Loop While condition
To exit from these loops prematurely use:
Exit Do
For Structure
The For loop structure is as follows:
For condition = x To x [Step x]
statements
Next
To exit from this loop prematurely use:
Exit For
Sub Procedures
Sub procedures are created with the following structure:
[Static] Sub name (Argument List)
statements
End Sub
For instance:
Sub printMessage(str As String)
MsgBox(str)
End Sub
This procedure is called as follows:
- From inside the same module : printMessage str
or : Call printMessage(str)
- From a different module : moduleName.printMessage(str)
Arguments can also be passed by value:
Public Sub printMessage(ByVal str As String)
Arguments can be made optional:
Sub printMessage(str1 As String, Optional str2 As String)
These optional arguments can be given default values:
Sub printMessage(str1 As String, Optional str2 As String = "Hello World")
Or we can give them values when we call them with the := operator:
printMessage str2:= "hello world"
This allows optional arguments in the argument list to be skipped
Function Procedures
Functions, which can return a value, have the following structure:
[Static] Function name(argument list) [As return value]
statements
End Function
For instance:
Function cube(number As Integer) As Integer
cube = number *number * number
End Function
Functions are called as follows:
value = cube(5)
or
cube 5
Property Procedured
These are used to set the values of private module variables:
Property Get procedureName () As return value
procedureName = varaiable
End Property
They can also take the form
Property Let procedureName (value As type)
Modules
Once Classes/Modules have been created with a .cls extension they are declared and used as follows:
Dim c1 As classname
Set c1 = New classname
The constructors and destructors are in the following procedures:
Private Sub Class_Initialize()
Private Sub Class_Terminate()
Classes can be destroyed as follows
Set c1 = Nothing
The states of Visual Basic
Visual Basic applications can be viewed in three different states :
1- Design
2- Execution
3- Break
In Design state you can edit the user interface or add code to application all the Windows of the IDE and its commands are available.
In Execution name state of the window of IDE are available. You can neither edit the user interface nor code to an application while it’s running.
In a Break state the application execution has been interrupted temporarily and can resume when you press F5 or choose run>continue. The immediate window is activated and you can edit the code and issue commands in it. However, you can’t edit the user interface.
Reasons for choosing Visual Basic 6.0 as Front end tool:
1- Integrated Development.
2- There is restriction for the number of controls is an application.
3- The Programmer has the facility to design the interface just by the dragging and releasing the components on the form.
All the methods and properties of all the components are pre defined
DATABASE PROGRAMMING WITH VISUAL BASIC
Nearly all business applications need to store large volumes of data organized in a format that simplifies retrieval. This is accomplished with a database management system (DBMS), a mechanism for manipulating tabular data with high level commands. The database management system hides low level details, such as how data are stored in a database.
Visual Basic provides a wealth of tools for creating and accessing databases on both individual machines and networks. The two major tools are:
1- The data control
2- The data access object
The data control give access to database without any programming. We can set a few properties of the control and use regular controls such as textboxes to display the values of the fields in the database.
The data access object is a structure of objects for accessing databases through our code.
DATABASE
A database is simply a grouping of related information organized for easy processing and retrieval. The actual data in a database is stored in tables, which are similar to random access files. Data in a table is made up of columns and rows. The rows contain identically structured pieces of information, which are equivalent to records of random access files. A record is a collection of values (called fields).
RECORDSETS
Record sets are objects that represent collection of records from one or more tables. We can’t access the tables of a database directly. The only way to view or manipulate records is via record set objects. A record set is constructed of columns and rows and is similar to a table, but it can contain data from multiple tables. The three types of record sets are:
Dynasts, which are updatable, view of data.
Snapshots, which are static (read-only) views of data
Tables, which are direct views of tables
Dynasts and snapshots are usually created with SQL statements. The table record set is a reference to a table in the database. The table is faster than the other types of Record sets, always in sync with the table’s data and can be used to update the database. But the table type is limited to a single table.
The Data Control’s Properties
The most important properties of the Data control are:
Database name, which specifies the database to be used
Record source, which specifies the part of the database seen by the control
At any given time, the Data Control is positioned at a single row (record) of its Record set. The user can move to any other record with the help of navigation buttons on the data control. The textbox controls are connected to a field of the Record Set through the Data control, and they are called data-bound (they have been bounded to afield in the record set).
The most important properties of data-bound control are:
Data source, which is the name of a Data control through which the controls (Text Box, Check Box) are bound to a Data control; in other words, it’s the name of a Data control through which the data bound control “sees” the database.
Data Field, which is the name of a field in the Record Set that the control displays and updates
The Data Control’s Methods
The simplest methods are the navigation methods, which is corresponds to the actions of the four buttons on the control, and they are as follows:
1- Move First repositions the control to the first record
2- Move Last repositions the control to the last record
3- Move Previous repositions the control to the previous record
4- Moe Next repositions the control to the next record
RELATIONAL CONCEPTS
The foundation of a relational database system is to break the data into multiple tables that are related by common information (keys). Keys connect the rows in one table to rows in another table. The keys establish relationships among the tables and make it possible to break the information into separate tables and avoid duplicating information.
The Primary Key
In a relational database system, each record has a unique identifier that is used to indicate the record and to relate it to other records in other tables. This identifier makes each record unique, and called composite primary key.
THE ACTIVE DATA OBJECTS
Visual basic supports several data access tools, with the Active Data Objects (ADO) being the most recent addition. Whereas the first visual basic data access tools (the Data Access Objects) allowed programmers to Access database only, ADO can access all major databases.
With ADO Visual Basic application sees three objects:
1- A connection object, which establishes a connection to the database, be it a local file or a remote SQL server.
2- A Command object, which executes commands against the database
3- A Record set object, which holds the records retrieved from the database or the records to be updated on the database.
Creating a Data Project
A Data Project is not a special project type. It’s basically a Standard EXE project, but Visual Basic loads all the database tools into the project’s Toolbox.
In the Project Explorer window, Visual Basic display a new form, and two Active X Designers. Database applications rely on two basic components:
1- One or more Data Environment component(s)
2- One or more Data Report component(s)
The Data Environment component lets we design a connection to a database and retrieve the desired records. The Data Report components lets we design reports and use them from within our applications.
To access a database with ADO (or any other data tool), we need two types of objects:
1- One or more connection objects
2- One or more command objects
The Connection object connects our application to a database, and the Command object retrieves records from the database.
No comments:
Post a Comment