Académique Documents
Professionnel Documents
Culture Documents
Snapshot
Introduction to client/ server technology
Front end tools – an introduction
Programming process
Visual basic integrated
Development environment
Basic program structure
1.1.1 Client /Server Architecture consist of three components, each one focusing on a
specified job.
They are:
A Database
A Client Application
A Network Connecting the Client and Server
Database Server
This component takes care of storing the clients information in a database, maintaining data
integrity and controlling database access.
Client Application
This component deals with the interface of the client application, performing validations
requesting and retrieving information to and from the database server.
Network
This components is the actual medium through which the data is transmitted between the
client and the server.
The computer programming is an extremely complex task made up many individual phases
all of which are important and all of which contribute to the solution of a problem.
The process of writing a program is called programming
Defining a problem: The programmer generally omits this step. But this step is absolutely
necessary for creating a workable solution. Before working on a project the programmer
should fully understand what exactly the user wants to do.
Outlining the solution: The program is generally not doing a single task. A program is built
up of certain small modules. Many programmers write the different modules, it becomes
extremely important to specify both the responsibilities of each task and how these individual
task iterate and interact. So, it has to ensure that the pieces being developed separately are
integrated into a whole system.
Selecting and representing algorithms: The previous two steps are used to do the primitive
work of problem solving. The third step is to represent the problem in algorithmic way that is
designed by the programmer. This step is extremely important because it describes the details
of the proposed problem and it’s solution.
Coding: After defining a problem and sketching out the details of the algorithm the next step
is to code the process. Before doing the coding process the programmer has to choose a
computer language.
Debugging: The programmer has to locate and correct all the inevitable errors. This step is
time consuming and often tiresome.
Testing and validation: This is the most important step because the whole program is
useless unit it produces a correct result. After debugging a program the main job the program
gives the test that the result are correct and it does the same in all cases. Also the program
gives the proper error messages when the input data is wrong.
Program maintenance: The programs are not static in nature and they frequently become
outdated as errors are discovered, new problems need to be solved, reviews are needed when
new equipment becomes available. So, the development of the program may be done by one
programmer and the modification by another programmer. So, the programmer who is
involved in the modification has to read the code and has to understand it. So, the program
written should; well documented clear and systematic so that, any one can easily understand
it and do the modification.
Process Employee
Validate Payroll Transaction
Create Payroll Cheque
Create Current Week Error Listing
Calculating Gross Salary
Calculate Voluntary Deductions
Process unmatched Employees
Updated Master payroll file
Update Master labour Distribution file
Calculate
Calculate mandatory Deductions
Each programmer, out of several at disposal can be entrusted with a module for writing and
testing thereby speeding up to the write up. The group leader can then combine these and test
the employee payroll file program.
A great advantage of modularized programming is that any changes in an application which
are bound to occur now and then affect only one or a few modules which can be modified at a
much lower cost than would have been the case for reprogramming in entirety.
The subroutines are those subsets of instructions amongst who are used with in a program.
These subroutines are used application and system programs. They are written once and for
all the computer manufactures or software agencies or the user himself.
Modules arise a section of a program into logical units just for the convenience of writing and
debugging. They may or may not appear over and again in the same program or different
programs. In other words, a subroutine is a module also but a module may or may not be a
subroutine.
Clarity: Clarity refers to the overall readability of the program and it is important to give
emphasis on its underlying logic. If a program is clearly written. It should be possible for
another program to follow the program logic with ease.
Efficiency: Efficiency is an important characteristic of a program. It is concerned with
execution speed and effective memory utilization. Many complex programs require a trade
off between speed and memory utilization.
User Friendly: The end user who is using the software is not consulted with what is
happening inside the program. He requires the results. The program must be user friendly so
that the user can easily communicate with the program. Proper messages are to be given.
Whenever the required comments are to be written in the program.
Reliable: The program must be reliable that is it is able to handle the situations when the
wrong inputs are given.
Portable: The program which is written must be able to run on different platforms without
doing many changes.
1.4.1 Features of VB
The compiler in Visual basic gives many different options for optimizing the
compiled code Such as optimization of fast Code. The Visual Basic is a very open
environment that supports the client/ Server architecture, Active X, Component Object Model
(COM), Distributed Component Object Model (DCOM). It also supports Open Database
Connectivity (ODBC).
A new feature that Microsoft calls IntelliSense enables the system to react in real time
during coding. There are five basic IntelliSense features. They are:
Quick Info is a feature that presents the syntax of the procedure. Which is being typed in a
Tool Tip like window. It even goes one step further in that it will bold the specific parameter
which is being coded in real time.
Complete word is a feature that automatically completes the word, which is typed in real
time, after enough characters that make the word distinct within the list of available words
has been typed.
Data Tips is the very useful feature that simply shows the value of the variable in a yellow
tool tip format at runtime.
List Constants is a feature that works the same as List Members feature except that with this
features available constant values for a given property are listed.
Some of the features are multiple projects can be loaded into the IDE-Integrated
Development Environment and treated as one. For example a standard project and an
ActiveX project can be loaded at the same time. This saves tremendous amount of time for
coding and debugging.
File Edit View Project Format Debug Run Tools Add-Ins Window Help
The project window tool bar contains three buttons, namely View code, View object and
Toggle Folders
Alphabetic Categorized
Form1 Form
(Name) Form1
Appearance 1-3D
Auto Redraw False
Back color &H8000000F&
Border Style 2-Sizable
Caption Form 1
Clip Control True
Control Box True
Draw mode 13-copy pen
Caption
Returns/sets the text displayed in an object’s title bar or
below an object’s icon.
1.7 CONTROLS
A control is an object that can be drawn on a form object to enhance user interaction with the
application.
The Tool Box Window contains various Controls. The Control or the objects placed in a form
at design Time. Select the Control with the Mouse the pointer, pointer changes to plus and
then draw in the form in the position wherever required.
Hint:
Double Click on Control will place the Control at the center of the form. Then it can
be sized and moved to the requirement.
Additional Controls can be added to the Tool Box by selecting the component menu
item in the project menu.
They respond to events initiated by the user or triggered by the system. They are classified
into 3 categories:
Label
Text Box
Command Button
List Box
Combo Box
Check Box
Option Button
Label
A
A label is a graphical control used to display text and is normally used to identify controls
that do not have a caption property.
Properties
Name The name or ID to refer it in the code.
Caption TO set the text which is visible to the user. By default its value is name
given in “Name” property.
Auto Size Sets or retrieves the ability of a control to resize to fit the contents of the
caption property. It is a Boolean property. Default value is False
Alignment To position the text. By default it is Left Alignment.
Visible To Specify the Label should be Visible or not for the User.
It is a Boolean property. Default value is true.
Text Box
It is used to accept input from the user as to display the information to the user.
Properties.
Name Determines the name of the Text Box which is used to refer it in the code.
Text Returns or sets the text in the edit area of the Text Box
Max Length Determines the maximum number of characters that can be entered in the
box.
Default value is 0 and maximum is 32000 characters.
Multilane To invoke the Text Wrap Feature
Enabled Determines whether the Text Box should respond to user generated event.
Password Char Determines the character to be displayed when the password is typed.
Command Button
Command button is a control that is most commonly used in a user interface and is generally
used to initiate, interrupt or end a particular process.
Properties
Name The name or ID refer it in the code
Caption To set the text which is visible to the user. By
default its value is name given in “Name”
property
Example Form 1
Label
LOGIN
Text Box
User Name
Command
Password Button
Ok Cancel
LOGIN: Property
Property Setting
Name 1-bllogin
Alignment 2-Center
Property Setting
Name Text name
Max Length 30
Text Empty
Property Setting
Name Text pass
Max Length 6
Password Char *
Text Empty
Property Setting
Name Cmdok
Caption OK
Form 1
CLICK ME
Property Setting
Name Cm click me
Caption CLICK & ME
List Box
A List Box is a control that displays a list of items from which the user can select one
or more items. If the number of items exceeds the display area of the list gets scroll bars
automatically.
To add items to the List Box at design item select the list property of the List Box and add
items to it. Press Ctrl+Enter after item is added.
Combo Box
Combo box is a control that contains both the features of a text box and a List Box.
This is used incases where the user can select an item from the list or selecting an item by
typing the text in the combo box.
There are three types of combo box
Dropdown Combo (style 0)
Simple Combo (style 1)
Dropdown List (style 2)
Dropdown Combo
This type has an edit area with a down arrow button appears initially. The list items
are hidden until the user click the down arrow button. Once the user clicks the down arrow
buttons the list items are dropped down from which the user can select the required item. This
is the default combo box.
Simple Combo
This combo box displays the list items all the time. It displays an edit area with an
attached list box, which is always visible.
Option Button
Option buttons or radio buttons appear in-groups. At any point of time the user can
select only one button. It is similar to toggle button. The main property of the option button is
checked and it is true if the control is checked it is false.
Check box
This presents one or more choices that the user can select, Main property of the
control is value and it is 0 if the checkbox is cleared and I if the checkbox is checked. This
also acts a toggle button.
B Shape
B When the line is not enough, this one supports rectangles anf ellipses/circles. As with the
line control, use its items to create animation.
OLE Container
If the object which come from other applications (such as Word, Excel,…….) is to be added
on to the VB application then this control is very useful.
Frame
It’s just a container- it can hold other controls. There are two very good reasons to use it. If
we want multiple groups of option buttons then place each group in a frame and each group
will operate independently. To manipulate control as a group (i.e., positioning then put them
in a frame and handle them all at one time.
Timer
This is the most unusual of the intrinsic control. By setting the INTERVAL property this
control will automatically create an event on a regular basis. No other control does this!. This
can be used to create an action at a certain time and then turn the control off to prevent
repeats.
Design mode is the mode in which most of the designing activities take place. When the
application is executing it is said to be in Run mode and when some error occurs while
execution the application enters into break mode.
Most of the properties of an object can be set at both Design time and run time. Some
properties can be set at design time by using properties window. There are some properties
that are not available at design time.
Examples
Setting run time property of textbox named-txt name
Txtname.Font.Italic=true
Txtname.Font.Size =24
Txtname.Font.= “Visual Basic”
Caption Determines the text which has to appear in the bar of the form
Name Specifies the name of the form, which is used to refer it in code.
Window State Normal, Maximized or Minimized.
1.9.1 Events
A form or control receives an event.
The event can be caused
By the user i.e. Keystroke
By the system i.e. Timer Events
By the code i.e. Load Event
Many events occur in conjunction with other events i.e. Mouse up, Mouse Down, Click
Events
Key Pres
To find which key was pressed. This event is frequently to write key events for textboxes
because this event takes place before the character is pressed or displayed in a textbox.
Change
The change event is triggered by various controls when their contents change.
Got Focus, Lost Focus
When the focus is moved from one control to the other, the first control receives the
Lost Focus event, and the second control receives the Got Focus event.
Example 1
Private sub text1 _ key press (Key ASCII as Integer)
End Sub
The Key Ascii argument is the ASCII character of the key pressed. The following event
allows the user to enter only numbers
Mouse Move
This event takes place continuously as the mouse moves over the control.
1.9.2 Methods
Each control has its own independent set of method that helps us in performing
actions. Methods can be invoked only during runtime.
Cls method
Used to clear the form
Eg. Forml.cls
Print Method
VB prints the text form the top left corner (0.0)
Eg. Forml. Print “Welcome to Learn VB”
Hide Method
This method is used to hide the form off the screen.
Eg. Froml. Hide
Show Method
Show the form that is loaded in the memory on the screen.
Load form
Froml. show
i.e., The variable name allows the user to refer to the value in the variable and the data type
determines the type of data that the variable can store.
Eg. Rno as Integer
Variable Rno stores the value of rollno which is a numeric input
1.11.2 Variables
Variables are the placeholders in which data can be stored and is accessed whenever
required. In other words variables are named location in memory that can store a value.
A variable has two parts name and data type. It can store data of specific type. The variable
name allows the user to refer to the value in the variable and the data type determines the type
of data that the variable can store.
Declaring Variable
General syntax for declaring a variable is
Dim < Variable name> As type
Eg: Dim Rno as integer
Dim name As String
o.e., Dim and As are keywords
The variable name is the “identifier”, used to identify the data.
The As clause of the Dim statement is optional. If no data type is specified to the variable, the
variable is allotted the Variant data type and initialized as Empty
Example 1:
Dim b the variable b is variant type, can store any data such as
1.11.4 Constants
Constant refers to the value that will not be changed during the execution of a
program. Once a constant has been declared, its value cannot be changed in subsequent
statements. Usually the constants are processed faster than variables, because the compiler
automatically substitutes constant names with their values.
Declaring the constant variable is similar to the declaring the variables, except that in
addition to the constant variable name, a value must also be mentioned.
Local Scope
A variable is said to have a local scope when it was decaled inside a function,
subroutine or an event. That is it can be accessed only within the function or procedure. The
value of variable is lost when the execution of procedure is completed.
Module Scope
A variable can be declared with module scope by using Private declaration statement.
The private declaration statement is the same as that of the Dim statement except the Dim
keyword is replaces with private keyword.
Global Scope
Global Scope variables are those variables that can be accessed in all procedures in all
modules of a project. Global Scope variables are declares using the Public keyword in the
general declaration section.
Scope of variable
Declaration
Type Used to declare variables in procedures. Each time the procedure is called, the data
stored in variables declared with this keyword are reset (eg. an Integer data
type will be reset to zero).
Static used to declare variables in procedures. Each time the procedure is called, the data
stored in variables declared with this keyword are retained.
Public used to declare variables within a module. The variable is available to all procedures
in the project.
Private Used to declare variables within a module. The variable is only available to
procedures within the project.
Re Dim The ReDim keyword is used to re-dimension an array.
1.11.9 Operators
An operator is a symbol specifying an action that is performed on one or more
expressions. The different types of operators are:
Operator Meaning
+ addition
- Subtraction
* Multiplication
/ Division
% (Modulo) Returns the remainder of a division
Comparison Operators: Operators which test whether two expressions are same or not
Operator Meaning
< Lesser than
> Greater than
= Equal to
<= Lesser than or Equal to
>= Greater than or Equal to
<> Not equal to
Logical Operators: Operators that evaluate some condition and returns True or False
Operator Meaning
AND Returns TRUE if both Boolean expressions are TRUE
OR Returns TRUE if either Boolean expressions is TRUE
Returns TRUE if both Boolean expressions are TRUE
1.12 Arrays
A standard structure for storing data in any programming language is an Array. Arrays
can hold sets of related data but the individual variables can hold single entities. Such as
a number, date or string. Arrays have upper and lower bounds and the elements have to
lie within those bounds.
Declaring Arrays
Unlike, simple variables arrays must be declared with the Dim statement followed by
the name of the array and the maximum number of elements it can hold in parentheses.
Dim sal (10)
In the above array, sal is the array that holds 11 values. Salary(0) is the first person
salary, salary 910 is the second person salary and so on.
In this case, the array will store 10 values, because the size of the array has been fixed.
Dynamic Array
There will be a situation when the user may not know the exact size of the array at
design time. Under such circumstances, a dynamic array can be initially declared and
elements can be added when needed instead of declaring the size of the array at design time.
With the use of the dynamic array it is possible to discard the data and return the resources it
occupied to the system, when it is no longer needed.
To create a dynamic array, declare it as usual with the Dim statement or public or private but
do not specify the dimensions.
Dim my array ()
Later in the program, depending on the number of elements to be stored in the array, the
ReDim statement can be used mention the actual size of the dimension.
When ReDim is executed, it forces the application to carry out an action at runtime. ReDim
statements are not executable and they can outside procedures.
Preserved keyword
Each time the ReDim statement id executed all the values currently stored in the array
are lost. Visual Basic resets the values of the elements as if they were just declared. The array
size can be changed without losing the existing data. The ReDim statement recognizes the
Preserve Keyword, which force it to resize the array without discarding the existing data.
For example user can increase an array without losing the values of the existing elements by
using the Ubound() functions.
Multidimensional Array
A multidimensional array is used when one needs to represent or store related information of
different dimensions. For example to hold the student registration number and marks of the
student, we need to mention the x and y co-ordinates.
It is possible to declare lower limits for one or both the dimensions as for fixed size arrays.
Dim my array 951 to 100, 1 to 50)
If … Then Statement
If … then block is used for conditional execution of one or more statements
Dim a As integer
Dim b As Integer
a=5
b=5
if a = b Then
Ms Box “ both Values are Equal”
End if
Dim a As Integer
Dim b As Integer
Dim c As Integer
If a > b Then
If a > c Then
MsgBox “A is greatest”
Else
If c > b then
MsgBox “c is greatest”
End If
End If
Else
If b > c Then
MsgBox “B is greatest”
Else
MsgBox “c is greatest”
End If
End If
End Sub
DoLoop … while
This statement structure first executes the statement and then checks the condition after each
execution.
1.14 Modules
A module is a collection of Procedure, Function and Events. Collection of modules form a
project or an Application
There are three types of Modules
Form module : It contains the code in the form itself. The extension is FRM
Standard module : It stores the code which can be used at different locations within the
project. The Extension is BAS
Class module : It implements object oriented programming concept in Visual basic.
Can create new Objects, Methods, Properties and Events by writing
code in class module the extension is CLS
Procedures
The Visual Basic Programs can be broken into smaller logical components called
procedures. Procedures are divided into logical units. They act as a building block for other
programs with slight modifications. Procedures are useful for implementing repeated tasks,
such as frequently used calculations.
A procedure can be a
Sub Procedure
Property Procedure
Function Procedure
Arglist is a list of argument name separated by commas. Each argument acts like a variable
in the procedure.
Two types of procedures
1. General procedures
2. Event procedure.
General procedures
This is where several event procedures perform the same actions. It is a good programming
practice to write common statements in a separate procedure and thaen call them in the event
procedure.
To add a General procedure:
1. The code window is opened for the module to which the procedure is to be added
2. The Add procedure option is chosen from the Tools menu.
3. The name of the procedure is typed in the text box.
Event procedure
Event procedure is a procedure block that the actual name of the controls. When an object in
Visual Basic recognizes that an event has occurred, it automatically invokes the event
procedure using the name corresponding to the event. Event procedures are said to be
attached to forms and controls. An event procedure for a control combines the control’s
actual name, an underscore, and the event name. For instance, to write a command button
click event to to invoke procedure when it is clicked, the command_click() event is used.