COMFIESTA



Unit – I

Introduction – Client/Server – Benefits of Client/Server – Downsizing – Upsizing – Right sizing – Client/Server Models – Distributed Presentation – Remote Presentation – Remote Data – Distributed Logic – Distributed Data – Client/Server Architecture – Technical Architecture – Application Architecture – Two Tier Architecture – Three Tier Architecture OLTP & n Tier Architecture.

Unit – II

Introduction to Visual Basic – Steps in VB Application – Integrated Development Environment (IDE) – Menu Bar – Tool Bar – Project Explorer Window – Property Window – Toolbox – Properties, Methods and Events – Event Driven Programming – Working with Forms - Variables – Scope of Variables – Constants – Data Types.

Unit – III

Functions – Procedures – Control Structure : If - Switch – Select – For – While – Do While - Arrays – User Defined Data Types – Data Type Conversions - Operators – String Functions – Date and Time Functions.

Unit – IV

Creating and Using Standard Controls: Form, Label, Text box, Command Button, Check Box, Option Button, List Box, Combo Box, Picture Box, Image Controls, Scroll Bars – Drive List Box – Directory List Box - Time Control, Frame, Shape and Line Controls – Control Arrays – Dialog Boxes - Single Document Interface (SDI) – Multiple Document Interface (MDI) – Menus – Menu Editor – Menu Creation.

Unit – V

Data Controls – Data Access Objects (DAO) – Accessing and Manipulating Databases – Recordset – Types of Recordset – Creating a Recordset – Modifying, Deleting Records – Finding Records - Data Report – Data Environment – Report - Designer – Connection Object – Command Object – Section of the Data Report Designer – Data Report Controls.

Unit – I

Introduction – Client/Server – Benefits of Client/Server – Downsizing – Upsizing – Right sizing – Client/Server Models – Distributed Presentation – Remote Presentation – Remote Data – Distributed Logic – Distributed Data – Client/Server Architecture – Technical Architecture – Application Architecture – Two Tier Architecture – Three Tier Architecture OLTP & n Tier Architecture

What is meant by client and server?

A network is set up between client system and server system to communicate with each other is called client/server network.

The computer requesting information is called a client.

The computer responding to the request is called a server.

The individual computers is called clients.

Client-Server Models:

■ Distributed Presentation

■ Remote Presentation

■ Distributed Logic

■ Remote Data

■ Distributed Data

Client/server:

The splitting of an application into tasks performed on separate computers connected over a network. In most cases, the “client” is a desktop computing device (e.g., a PC) or a program “served” by another networked computing device (i.e., the “server”). Gartner has defined five styles of client/server computing, based on how presentation, application logic and data management functions are partitioned between the client and server device — see separate definitions for “distributed presentation,” “remote presentation,” “distributed function,” “remote data management” and “distributed data management.”

Along the range there are at least five points:

1.Distributed presentation: The server and the client partly handle the presentation

2.Remote presentation: The client handles or controls the entire presentation

3.Distributed logic: The server and the client partly handle the application logic

4.Remote data management: The server handles or controls the entire Database management

5. Distributed database: The server and the client partly handle the Database management

In client/server the client controls part of the activity, but in hierarchical processing the host controls all activity. A client PC almost always does the following in a client/server environment: screen handling, menu or command interpretation, data entry, help processing, and error recovery.

The dividing line between the client and a server can be anywhere along a broad continuum: at one end only the user interface has been moved onto the client; at the other, almost all applications have been moved onto the client and the database may be distributed. There are atsleast five points along the continuum:

Distributed presentation:

The presentation is handled partly by the server and partly by the client.

Remote presentation:

The presentation is controlled and handled entirely by the client.

Distributed logic:

The application logic is handled partly by the server and partly by the client.

Remote data management:

Database management is controlled and handled entirely by the server.

Distributed database:

Database management is handled partly by the server and partly by the client. There are,

therefore, two major applications for client/server in a library environment:

1) as the architecture for an automated library system, and

2) as an approach to linking heterogeneous systems.

In the first application, a vendor designs a system using client/server architecture to facilitate use

of that system to access multiple servers, to facilitate bringing together multiple product lines,

and/or to improve productivity. In the second application, a vendor designs a client to facilitate.

Layers of the Client/Server Logic

Distributed Presentation:

Distributed presentation is often referred to as screen scraping. It is implemented with products which capture an existing screen image prepared on the server (usually a mainframe 3270 image) and manipulates it as a GUI at the workstation.

Although it sounds simplistic, current products are highly sophisticated. They can direct a single data input to several applications, integrate data from several applications in one GUI and interface to data and products running on the workstation.

When to Use

- Adding client/server to existing applications

- Integrating multiple, existing applications on a workstation

- Supporting many terminal users and a small number of PC users

- Integrating mainframe application data into PC products

Remote Presentation

Remote presentation involves the presentation component running on the client and all of the processing taking place on the server. This architecture is often employed where there are diverse platforms for client workstations. There are a variety of portable GUI development tools on the market.

This architecture is safe for transaction processing as the actual business processing is at the same location as the data. It is therefore less at risk from network failure.

When to Use

- Multiple operating system environments for client workstations

- Highly data centered processing

- Low powered client PCs

- Simple transaction processing

Distributed Function

This is perhaps the most complex environment to implement due to the need to synchronize processes running on both client and server. The data remains server based but processing is running on both client and server.

When to Use

- Mix of data and presentation level processing

- Highly complex processing demands

- Downsizing existing mainframe application

Remote Data Management

The remote data management architecture has all of the application running on the client but the data remains on the server. It is a common model for new client server applications, driven largely by the capabilities of common tools.

Depending on the DBMS in use, there may be some business functionality running on the server (in the DBMS as triggers and stored procedures).

When to Use

- Powerful workstation

- Presentation oriented processing

- Shared access to data

- Upsizing of existing PC application

Distributed Database

In the distributed database architecture, the data is stored on several servers or it may be split across the client and the server.

The distribution model used and the complexity of the transactions will determine how complex the implementation of distributed databases will be.

When to Use

- Naturally segmented database and discrete usage

- Simple (single location, single table) updates

Types of Client/Server Computing

The Gartner Group came out with the five ways of describing the different c/s styles based on how they split the three components of any application: user interface, business or application logic, data management. The five styles are distributed presentation, remote presentation, distributed function, remote data management, and distributed data management. (Note: This is an arbitary classification and others may do it differently).

|Types of Client/Server Computing |

|C/S Type |Distributed |Remote Presentation |Distributed Logic |Remote Data |Distributed Database |

| |Presentation | | |Management | |

|Functions on Server |Data Mgt. |Data Mgt. |Data Mgt. |Data Mgt. |Data Mgt. |

|Side |Business Logic |Business Logic |Business Logic | | |

| |User Interface | | | | |

|Network over which the processes communicate |

|Functions on Client |User Interface |User Interface |Business Logic |Business Logic |Data Mgt. |

|Side | | |User Interface |User Interface |Business Logic |

| | | | | |User Interface |

Distributed and Remote Presentation -- For people whose roots are embedded in the mainframe IBM world, client-server is essentially distributed or remote presentation. This style maps a workstation Graphical User Interface (GUI) front end onto an existing application's text-based screen. In Distributed Presentation, we are generally looking at a system which uses a dumb terminal at the client side. This is the extreme of the 'thin' client model (see below).

Distributed Logic -- Here the split occurs in the application functionality, one part going to the client, other to the server. Distributed Logic applications are the most complex of the three basic typologies since two separately compiled application programs must be developed. Developers must analyze where each function should reside and what type of dialog must occur between the two programs. The underlying communications facilities may implement either a message-based or remote procedure call (RPC) mechanism for transfer of dialog and data.

Remote Data Management -- In remote data management, the entire application resides on the client and the data management is located on a remote server/host. Remote Data Management is relatively easily to program for because there is just one application program.

Distributed Database -- This is when data management and application functions occur at both the client and server. In this instance, data management at the client would include referential, read-only data. Data frequently updated or accessed by many users would reside on the server. This is the extreme of the 'fat' client model.

Client/server architecture:

A network architecture in which each computer or process on the network is either a client or a server. Servers are powerful computers or processes dedicated to managing disk drives (file servers), printers (print servers), or network traffic (network servers ). Clients are PCs or workstations on which users run applications. Clients rely on servers for resources, such as files, devices, and even processing power.

Another type of network architecture is known as a peer-to-peer architecture because each node has equivalent responsibilities. Both client/server and peer-to-peer architectures are widely used, and each has unique advantages and disadvantages.

Client-server architectures are sometimes called two-tier architectures.

[pic]

[pic]

Technical Architecture:

[pic]

Technology that separates computers and application software into two categories clients, and servers to better employ available computing resources and share data processing loads. A client computer provides the user interaction-facility (interface) and some or all application processing, while the a server computer might provide high-volume storage capacity, heavy data crunching, and/or high resolution graphics. Typically, several client computers are connected through a network (or networks) to a server which could be a large PC, minicomputer, or a mainframe computer. Every computer connected to a website acts as a client while the website's computer acts as a server. Also called client-server environment.

Application architecture:

Application architecture is one of several architecture domains that form the pillars of an enterprise architecture or solution architecture. Note that the term "application architecture" (without the s) is commonly used for the internal structure of an application, for its software modularisation.

Applications Architecture is the science and art of ensuring the suite of applications being used by an organization to create the composite application is scalable, reliable, available and manageable.

One not only needs to understand and manage the dynamics of the functionalities the composite application is implementing but also help formulate the deployment strategy and keep an eye out for technological risks that could jeopardize the growth and/or operations of the organization.

Applications Architecture means managing how multiple applications are poised to work together. It is different from software architecture, which deals with design concerns of one application.

[pic]

[pic]

Client Server Application architecture

There will be a server application accessing windows service or web service. The client application will have Multiple Document Interface.

The client application will use socket connectivity with server application so as to get authenticated from server, and also to track record of client connections over server.

The service will be a web service

After successful authentication the client application will directly access web service so there will be no overloading on server.

Introduction to 2-Tier Architecture:

2-tier architecture is used to describe client/server systems where the client requests resources and the server responds directly to the request, using its own resources. This means that the server does not call on another application in order to provide part of the service.

[pic]

Two-Tier Architecture:

The two-tier architecture is like client server application. The direct communication takes place between client and server. There is no intermediate between client and server.

[pic]

The above figure shows the architecture of two-tier. Here the communication is one to one. Let us see the concept of two tier with real time application. For example now we have a need to save the employee details in database. The two tiers of two-tier architecture is

Database (Data tier)

Client Application (Client tier)

So, in client application the client writes the program for saving the record in SQL Server and thereby saving the data in the database.

Advantages:

Understanding and maintenances is easier.

Disadvantages:

Performance will be reduced when there are more users.

[pic]

[pic]

[pic]

Two-Tier Architecture

Three-tier architecture:

Multi-Tiered Architecture:

In 3-tier architecture, each server (tier 2 and 3) performs a specialised task (a service). A server can therefore use services from other servers in order to provide its own service. As a result, 3-tier architecture is potentially an n-tiered architecture

[pic]

Introduction to 3-Tier Architecture:

In 3-tier architecture, there is an intermediary level, meaning the architecture is generally split up between:

A client, i.e. the computer, which requests the resources, equipped with a user interface (usually a web browser) for presentation purposes

The application server (also called middleware), whose task it is to provide the requested resources, but by calling on another server

The data server, which provides the application server with the data it requires

[pic]

Three-Tier Architecture:

Three tier architecture having three layers. They are

Client layer

Business layer

Data layer

Client layer: Here we design the form using textbox, label etc.

Business layer: It is the intermediate layer which has the functions for client layer and it is used to make communication faster between client and data layer. It provides the business processes logic and the data access.

Data layer: it has the database.

`[pic]

Advantages:

Easy to modify with out affecting other modules

Fast communication

Performance will be good in three tier architecture.

[pic]

Visual overview of a Three-tiered application

Three-tier[3] is a client–server architecture in which the user interface, functional process logic ("business rules"), computer data storage and data access are developed and maintained as independent modules, most often on separate platforms. It was developed by John J. Donovan in Open Environment Corporation (OEC), a tools company he founded in Cambridge, Massachusetts.

The three-tier model is a software architecture and a software design pattern.

Three-tier architecture has the following three tiers:

Presentation tier

This is the topmost level of the application. The presentation tier displays information related to such services as browsing merchandise, purchasing, and shopping cart contents. It communicates with other tiers by outputting results to the browser/client tier and all other tiers in the network.

Application tier (business logic, logic tier, data access tier, or middle tier)

The logic tier is pulled out from the presentation tier and, as its own layer, it controls an application’s functionality by performing detailed processing.

Data tier

This tier consists of database servers. Here information is stored and retrieved. This tier keeps data neutral and independent from application servers or business logic. Giving data on its own tier also improves scalability and performance.

Comparing both types of architecture:

2-tier architecture is therefore a client-server architecture where the server is versatile, i.e. it is capable of directly responding to all of the client's resource requests.

In 3-tier architecture however, the server-level applications are remote from one another, i.e. each server is specialised with a certain task (for example: web server/database server). 3-tier architecture provides:

A greater degree of flexibility

Increased security, as security can be defined for each service, and at each level

Increased performance, as tasks are shared between servers

What are the advantages and disadvantages of client-server networking ?

Earlier we saw what is a client/server architecture? and its main difference from peer to peer network, i.e. in client server there was one powerful computer (known as server) which acts as a provider of information to other sub-ordinate workstations (called client). Now Let us discuss the benefits and drawbacks of Server-Client computing over P2P computing :-

Advantages of Client Server Networks :

1) Centralization : Unlike P2P, where there is no central administration, here in this architecture there is a centralized control. Servers help in administering the whole set-up. Access rights and resource allocation is done by Servers.

2) Proper Management : All the files are stored at the same place. In this way, management of files becomes easy. Also it becomes easier to find files.

3) Back-up and Recovery possible : As all the data is stored on server its easy to make a back-up of it. Also, in case of some break-down if data is lost, it can be recovered easily and efficiently. While in peer computing we have to take back-up at every workstation.

4) Upgradation and Scalability in Client-server set-up : Changes can be made easily by just upgrading the server. Also new resources and systems can be added by making necessary changes in server.

5) Accessibility : From various platforms in the network, server can be accessed remotely.

6) As new information is uploaded in database , each workstation need not have its own storage capacities increased (as may be the case in peer-to-peer systems). All the changes are made only in central computer on which server database exists.

7) Security : Rules defining security and access rights can be defined at the time of set-up of server.

8) Servers can play different roles for different clients.

Disadvantages of Client Server Architecture :

1) Congestion in Network :Too many requests from the clients may lead to congestion, which rarely takes place in P2P network. Overload can lead to breaking-down of servers. In peer-to-peer, the total bandwidth of the network increases as the number of peers increase.

2) Client-Server architecture is not as robust as a P2P and if the server fails, the whole network goes down. Also, if you are downloading a file from server and it gets abandoned due to some error, download stops altogether. However, if there would have been peers, they would have provided the broken parts of file.

3) Cost : It is very expensive to install and manage this type of computing.

4) You need professional IT people to maintain the servers and other technical details of network.

It can the summarized that client-server model is not used in small scale networks and networks where security is not a big issue.

Online transaction processing:

Online transaction processing, or OLTP, refers to a class of systems that facilitate and manage transaction-oriented applications, typically for data entry and retrieval transaction processing. The term is somewhat ambiguous; some understand a "transaction" in the context of computer or database transactions, while others (such as the Transaction Processing Performance Council) define it in terms of business or commercial transactions. OLTP has also been used to refer to processing in which the system responds immediately to user requests. An automatic teller machine (ATM) for a bank is an example of a commercial transaction processing application.

Requirements:

OLTP is a methodology to provide end users with access to large amounts of data in an intuitive and rapid manner to assist with deductions based on investigative reasoning.

Online transaction processing increasingly requires support for transactions that span a network and may include more than one company. For this reason, new online transaction processing software uses client or server processing and brokering software that allows transactions to run on different computer platforms in a network.

In large applications, efficient OLTP may depend on sophisticated transaction management software (such as CICS) and/or database optimization tactics to facilitate the processing of large numbers of concurrent updates to an OLTP-oriented database.

For even more demanding Decentralized database systems, OLTP brokering programs can distribute transaction processing among multiple computers on a network. OLTP is often integrated into service-oriented architecture (SOA) and Web services.

Benefits:

Online Transaction Processing has two key benefits: simplicity and efficiency. Reduced paper trails and the faster, more accurate forecasts for revenues and expenses are both examples of how OLTP makes things simpler for businesses.

Disadvantages:

As with any information processing system, security and reliability are important considerations. When organizations choose to rely on OLTP, operations can be severely impacted if the transaction system or database is unavailable due to data corruption, systems failure, or network availability issues. Additionally, like many modern online information technology solutions, some systems require offline maintenance which further affects the cost-benefit analysis.

OLTP (online transaction processing) is a class of program that facilitates and manages transaction-oriented applications, typically for data entry and retrieval transactions in a number of industries, including banking, airlines, mailorder, supermarkets, and manufacturers. Probably the most widely installed OLTP product is IBM's CICS (Customer Information Control System).

Today's online transaction processing increasingly requires support for transactions that span a network and may include more than one company. For this reason, new OLTP software uses client/server processing and brokering software that allows transactions to run on different computer platforms in a network.

Online Transaction Processing (OLTP)

Online Transaction Processing (OLTP) is a class of program that supports, facilitates and manages high-transaction-oriented applications. The term may be ambiguous because some understand a "transaction" in the context of computer or database transactions, while others define it in terms of business or commercial transactions. OLTP may also refer to processing in which the system responds immediately to user requests, such as a bank’s automatic teller machine (ATM). For our purposes, we use the first definition.

The primary features of OLTP are immediate client feedback and a high volume of individual transactions. For that reason it is typically used for data entry and retrieval transactions in industries that rely heavily on processing a large number of client transactions efficiently. These include banking, airlines, online retailers, supermarkets, and manufacturers.

In the transaction server, the client component usually includes GUI and the server components usually consists of SQL transactions against a database. These applications are called OLTP (Online Transaction Processing) OLTP Applications typically,

1. Receive a fixed set of inputs from remote clients.

2. Perform multiple pre-compiled SQL comments against a local database.

3. Commit the work and

4. Return a fixed set of results.

The N-tier Architecture :

An N-tier architecture uses several "tiers" of computers (servers) to interpret requests and transfer data between one place and another. The 0th tier is at the source of the data. Each tier is completely independent of all the other tiers, except for those immediately above and below it. The nth tier only has to know how to handle a request from the n+1th tier, and how to forward that request onto the n-1th tier (if there is one), and handle the results of the request.

In our case, we only have 2 (3 if you count the user application as a tier) tiers, with one of them being the actual database, or the 0th tier. Using a 1st tier (or middle tier), allows the client to be completely independent of the database. The client simply sends a request to the 1st tier, which interprets it and puts it in a form the 0th tier will understand, and sends it on to the 0th tier. The 0th tier then sends the result back to the 1st tier, which interprets it and packages it up in way the client will understand, and then sends it on to the client. The middle tier(s) does not spend much time interpreting a request and sending it on (only a couple milliseconds), so adding middle tier servers will not slow down the transfer (using a caching system in addition to the N-tier architecture actually speeds everything up).

The big advantage to using such an architecture is that the client does not need to know anything about the database. The client is completely removed from the database. The middle tier (our Frontier server) contains all the information about how to connect to the database, how to send a request, what the result will look like, etc; as well as information on how to send that result back to the client.

Another big advantage to using a middle tier is, since all the database connection protocols are in the middle tier, updates to the database become much easier to implement. Instead of making these changes in thousands of clients, they only need to be made in a few middle tier servers.

Apart from the usual advantages of modular software with well-defined interfaces, the three-tier architecture is intended to allow any of the three tiers to be upgraded or replaced independently in response to changes in requirements or technology. For example, a change of operating system in the presentation tier would only affect the user interface code.

Typically, the user interface runs on a desktop PC or workstation and uses a standard graphical user interface, functional process logic may consist of one or more separate modules running on a workstation or application server, and an RDBMS on a database server or mainframe contains the computer data storage logic. The middle tier may be multi-tiered itself (in which case the overall architecture is called an "n-tier architecture").

DIAGRAM FOR N-TIER ARCHITECTURE:

[pic]

The following sections define each layer of a n-tier architecture in more detail.

Data Access Layer

The function of components in the Data Access Layer is to separate data access from data storage. The purpose is to shield the rest of the application from the details of data storage, which makes applications easier to build and to maintain. For example, you might need to extend an application by changing the data source from a relational database to flat XML files. Such a change can be implemented in a single Data Access component rather than in multiple components throughout the application

Business Servicing Layer

The Business Servicing Layer contains the business logic and the processing components of an application. The components in this layer respond to events by taking certain actions. For example, when a price change occurs, update listings in a product catalog and notify sales reps.

The components in this layer also enforce business rules. For example, do not process an order if balance due is over thirty days old. Furthermore, the components in this layer are structured to create a workflow among related processes.

Presentation Layer

The Presentation Layer is the user interface component of an application. It is the point where an external user interacts with an application. Interaction can be direct (by data input) or indirect (by viewing data).

The Presentation Layer consists of three major components:

? User interface components (forms, buttons, menus, etc.).

? Controller logic that manages the binding between UI components and business logic in the Business Servicing Layer.

? Service elements (or models) that define the contract with the Business Servicing and the Data Access Layers.

Integration Layer

The Integration Layer is similar to the Presentation Layer. Where the Presentation Layer exposes the n-tier application to external users, the Integration Layer exposes the application to external systems. Integration can be data-centric, which involves moving data from one application to another. Integration can also be functional, which involves exposing an application’s business processes and logic as a service that can be used by external systems.

A two-tier architecture is where a client talks directly to a server, with no intervening server. It is typically used in small environments (less than 50 users).

A three tier is a client-server architecture in which the user interface is the 1st tier, the functional process logic ("business rules") is the second tier, the data storage and data access are the 3rd tier. Each tier is developed and maintained as independent modules, most often on separate servers.

An n-tier architecture is the extension of this concept where finer levels of functionality are distributed across multiple servers.

For example, are you asking from the perspective of software architecture, the design of a new communication protocol, etc? I will assume that you are asking about software architectures, as this is the most common context.

In software engineering, multi-tier architecture (often referred to as n-tier architecture) is a client server architecture in which more than one software agent usually running in different servers does the execution of an application. The reasons for multi-tier architectures are as follows:

1. Performance: allows for scalability by distributing the computation across multiple servers. Of course, a downfall of such strategy is when the communication costs are larger than the computation costs. In the old days, study of the decompositions of architectures was done by using queuing theory. A classic book in this area is the book by Kleinrock, Theory, Volume 1, Queueing Systems;

2. Security: by decomposition, different security strategies can be applied at each level of the hierarchy, and hence, this leads if properly designed to better security; and

3. Reliability and distribution: any layer of the architecture can be run in different servers, and therefore when a failure occurs, if properly designed, then a redirection to another server is possible. Of course for this to work a robust distributed architecture that often includes persistent transactions (a transaction that either completes or is roll back) are needed.

Multi-Layered Design:

The following diagram shows the multi-layered design that we will build in this seminar. This design uses 4 layers divided into Presentation, Business Logic, Data Access, and Data Storage.

Concentric circles are used to demonstrate that the layers only communicate with the adjacent layer and never skip a layer. That is the presentation layer only communicates with the business logic layer and the business logic layer only ever communicates with the data access layer.

[pic]

Describe a disconnected data access structure:

The problem described above leads us to the realization that we need to somehow have a disconnected access to our data if we are to have an architecture that will scale to web based applications. Now we could design a connected data architecture for our internal applications and use a different architecture for any web-based components that may arise in the future, but that would cause us to be using two differing application architectures and would totally prevent use from leveraging any work we did on the internal applications for our web requirements.

Instead we could design a disconnected data access mechanism that can be used in both the web-based environments and in our internal VFP applications. What we need is a data access mechanism that is disconnected and stateless. The diagram below shows the design we need to achieve.

[pic]

Difference between 2 or 3 tier architecture and n tier architecture:

Nowadays approach to IT systems architecture is 4-tier.

1st tier is a Presentation Layer: this is what user sees and clicks.

2nd tier is a Business Logic Layer (BLL): this is a set of rules how system has to behave and process data.

3rd tier is a Data Access Layer (DAL): this is a set of fuctions for retriving and manipulating data in database.

4th tier is a database: it contains data scheme, data itself and (if used) stored procedures.

If you have 2-tier or 3-tier architecure it means that some mentioned above layers are implemented together that borders between them disappeared and can be treated as 1.

In a 2 tier architecture the program (sourcecode and business logic) are separated from the database ( data, tables). Example: a factory application with a server that holds the program, a second server that holds the database and a socalled consol that is use as an interface to users.

In a 3 tier environment there is also a separate program running on the lokal PC. This program performs the local activities and communcates with the program running on the application server.

n- tier add an extra level between the PC and the rest. Using the internet is an example. You explorer is the local program. The server of your provider is the informaten broker. This is the extra level that holds the logic of combining messages and information from diverent sources and systems into 1 HTML page. For example. You're using a google bar. This part of the page get's it information from the main program that runs at the Google server, which in it's turn is connected to the google database.

Unit – II

Introduction to Visual Basic – Steps in VB Application – Integrated Development Environment (IDE) – Menu Bar – Tool Bar – Project Explorer Window – Property Window – Toolbox – Properties, Methods and Events – Event Driven Programming – Working with Forms - Variables – Scope of Variables – Constants – Data Types.

STEPS IN VB APPLICATION:

Figure 1 The Visual Basic startup dialog box

[pic]

Overview to the Integrated Development Environment (IDE).

The Visual Basic IDE appears in Figure 1.1, and as a Visual Basic programmer, this is where you’ll spend most of your programming time. If you’re not already familiar with the parts of the IDE, you will be in time.

 

[pic]

Figure-1-1- The Visual Basic Integrated Development Environment

Figure 1.1 The Visual Basic Integrated Development Environment.

The Visual Basic IDE has three distinct states: Design, Run, and Debug. The current state appears in Visual Basic’s title bar. This chapter concentrates on the Design state. We’ll cover the Debug state later. (In the Run state, Visual Basic is in the background while your program runs.)

The IDE is composed of these parts:

1. The Menu Bar

2. The Toolbar

3. The Project Explorer

4. The Properties Window

5. The Form Layout Window

6. The Toolbox

7. Form Designer

8. Code Window

9. The Immediate Window

1. The Menu Bar

The menu bar presents the Visual Basic menus you need to work with. The basic menus with their features are:

• File: contains the commands for opening projects, saving projects, creating executable files and list of recent project; also used for similar file handling option and printing option.

• Edit: contains standard editing functions like Undo, Copy, Paste plus a number of commands for formatting and editing your code like Find, Replace and so on.

• View: contains commands for displaying and hiding components from windows and toolbar.

• Project: sets project properties, adds/removes forms and modules, and add/removes references and components.

• Format: contains command for aligning or sizing the controls on the Form.

• Debug: contains the usual debugging command that starts/stops debugging and stepping through programs.

• Run: contains the commands that start, break, and end execution of the current application.

• Query: consists of the commands that are generally used for handling databases.

• Diagram: is used when building database applications to draw database diagrams.

• Tools: menu consists of the tools that you may need while building ActiveX components and ActiveX controls; contains the command to start the Menu Editor and the Options command, which lets you customize the environment.

• Add-Ins: contains Add-In manager, lists add-ins like Application Wizard and API Viewer.

• Window: arranges or selects open windows.

• Help: handles Help and the About box.

2. The Toolbar.

The main Visual Basic toolbar appears as in Figure 1.2. This toolbar contains buttons matching popular menu items, as you can see in Figure 1.2; clicking the button is the same as selecting a menu item and can save you some time.

 

[pic]

Figure-1-2-Main Toolbar

Figure 1.2 The Main Toolbar

Besides the main toolbar, you can also display other dock able toolbars in Visual Basic: the Debug, Edit, and Form Editor toolbars. To display one of these toolbars, just select it using the Toolbars item in the View menu; the toolbar appears.

• The Standard toolbar is just below the main menu bar and is displayed by default.

 

[pic]

Figure-1-3- Standard Toolbar

Figure 1.3 Standard Toolbar

• The Edit toolbar contains the commands of the Edit menu.

 

[pic]

Figure-1-4- Edit Toolbar

Figure 1.4 Edit Toolbar

• The Debug toolbar contains the commands of the Debug menu.

 

[pic]

Figure-1-5- Debug Toolbar

Figure 1.5 Debug Toolbar.

• The Form Editor Toolbar contains the commands of the Format menu.

 

[pic]

Figure-1-6- Form Editor toolbar

Figure 1.6 Form Editor toolbar

 

Opening and closing of toolbar can be done by choosing View > Toolbar, which then displays a submenu containing the names of the toolbars.

Creating a New Toolbar

To create a new toolbar, follow these steps:

[pic]

Figure-1-7-TCS Toolbar

a) Open customize dialog box, choose View >Toolbars > Customize.

b) On toolbar tab, click the New Tab.

c) Give name to new toolbar (in figure 1.7, it’s TCS Toolbar).

d) Add icons to your new menu from Commands tab, which contains all commands of the IDE’s menu.

e) Add the toolbar to your IDE and drag commands to the toolbar.

f) Add as many commands icons as necessary, and then close the Customize dialog box.

Project Explorer

Docked on the right side of the screen, just under the toolbar, is the Project Explorer window. The Project Explorer as shown in figure as a quick reference to the various elements of a project namely form, classes and modules. All of the object that make up the application are packed in a project. A simple project will typically contain one form, which is a window that is designed as part of a program's interface. It is possible to develop any number of forms for use in a program, although a program may consist of a single form. In addition to forms, the Project Explorer window also lists code modules and classes.

Figure 3 Project Explorer

[pic]

Properties Window

4. The Properties Window.

[pic]

Figure-1-9-The-Properties-Window

The Properties Window contains the property settings for the selected objects and controls. Properties are the attributes of an object and controls, such as its caption, backcolor, forecolor, size, font, height, and so on. Property Window is used to change the appearance, text/values displayed on the controls. Some properties can only be changed during design time and some can also be changed through codes at runtime.

To hide or unhide the Properties Window, choose View > Properties window (F4).

Toolbox

The Toolbox contains a set of controls that are used to place on a Form at design time thereby creating the user interface area. Additional controls can be included in the toolbox by using the Components menu item on the Project menu. A Toolbox is represented in figure 2 shown below.

Figure 2 Toolbox window with its controls available commonly.

[pic]

|Control |Description |

|Pointer |Provides a way to move and resize the controls form |

|PictureBox |Displays icons/bitmaps and metafiles. It displays text or acts as a visual container for other |

| |controls. |

|TextBox |Used to display message and enter text. |

|Frame |Serves as a visual and functional container for controls |

|CommandButton |Used to carry out the specified action when the user chooses it. |

|CheckBox |Displays a True/False or Yes/No option. |

|OptionButton |OptionButton control which is a part of an option group allows the user to select only one option |

| |even it displays mulitiple choices. |

|ListBox |Displays a list of items from which a user can select one. |

|ComboBox |Contains a TextBox and a ListBox. This allows the user to select an ietm from the dropdown ListBox,|

| |or to type in a selection in the TextBox. |

|HScrollBar and VScrollBar |These controls allow the user to select a value within the specified range of values |

|Timer |Executes the timer events at specified intervals of time |

|DriveListBox |Displays the valid disk drives and allows the user to select one of them. |

|DirListBox |Allows the user to select the directories and paths, which are displayed. |

|FileListBox |Displays a set of files from which a user can select the desired one. |

|Shape |Used to add shape (rectangle, square or circle) to a Form |

|Line |Used to draw straight line to the Form |

|Image |used to display images such as icons, bitmaps and metafiles. But less capability than the |

| |PictureBox |

|Data |Enables the use to connect to an existing database and display information from it. |

|OLE |Used to link or embed an object, display and manipulate data from other windows based applications.|

|Label |Displays a text that the user cannot modify or interact with. |

 Visual Basic 6.0 - Properties, Methods and Events

All the controls in the ToolBox except the Pointer are objects in Visual Basic. These objects have associated properties, methods and events.

Real world objects are loaded with properties. For example, a flower is loaded certain color, shape and fragrance. Similarly programming objects are loaded with properties. A property is a named attribute of a programming object. Properties define the characteristics of an object such as Size, Color etc. or sometimes the way in which it behaves. For example, a TextBox accepts properties such as Enabled, Font, MultiLine, Text, Visible, Width, etc.

• Enables property allows the TextBox to be enabled or disabled at run time depending on the condition set to True or False.

• Font property sets a particular font in the TextBox.

• MultiLine property allows the TextBox to accept and display multiple lines at run time.

• Text property of the TextBox control sets a particular text in the control.

• Visible property is used to hide the object at run time.

• Width property sets the TextBox to the desired width at design time.

The properties that are discussed above are design-time properties that can be set at the design time by selecting the Properties Window. But certain properties cannot be set at design time. For example, the CurrentX and CurrentY properties of a Form cannot be set at the design time.

A method is an action that can be performed on objects. For example, a cat is an object. Its properties might include long white hair, blue eyes, 3 pounds weight etc. A complete definition of cat must only encompass on its looks, but should also include a complete itemization of its activities. Therefore, a cat's methods might be move, jump, play, breath etc.

Similarly in object-oriented programming, a method is a connected or built-in procedure, a block of code that can be invoked to impart some action on a particular object. A method requires an object to provide them with a context. For example, the word Move has no meaning in Visual Basic, but the statement,

Text1.Move 700, 400

performs a very precise action. The TextBox control has other associated methods such as Refresh, SetFocus, etc.

• The Refresh method enforces a complete repaint of the control or a Form. For example, Text1.Refresh refreshes the TextBox.

• The Setfocus method moves the focus on the control. For Example Text1.SetFocus sets the focus to TextBox control Text1.

What Are Properties, Methods, and Events?

Put simply, properties describe objects. Methods cause an object to do something. Events are what happens when an object does something.

Every object, such as a form or control, has a set of properties that describe it. Although this set isn't identical for all objects, some properties--such as those listed in Table 6.1--are common to most controls. You can see every property for a given control by looking at the Properties window in the IDE.

TABLE 6.1  Common Properties of Visual Basic Controls

|Property |Description |

|Left |The position of the left side of a control with respect to its container |

|Top |The position of the top of a control with respect to its container |

|Height |A control's height |

|Width |A control's width |

|Name |The string value used to refer to a control |

|Enabled |The Boolean (True/False) value that determines whether users can manipulate the control |

|Visible |The Boolean (True/False) value that determines whether users can see the control |

Another important property to consider is BorderStyle, which determines the window elements (title bar, Maximize and Minimize buttons, and so forth) a form will have. Table 6.2 summarizes the six BorderStyle settings; Figure 6.1 shows the same form, displayed with each setting.

TABLE 6.2  The Six Settings of the BorderStyle Property

|Setting |Description |

|0-None |No borders, no title bar, not movable. Use this as a backdrop for a splash screen. |

|Setting |Description |

|1-Fixed Single |Not sizable by dragging borders but can have Maximize and Minimize buttons. Use this for any fixed-size window for |

| |which you want a button to appear in the taskbar. |

|2-Sizable (default) |Sizable by dragging borders and by using Maximize and Minimize buttons. Use this for typical programs. |

|3-Fixed Dialog |Not sizable and no Maximize/Minimize buttons. Use this for simple forms such as a password dialog. |

|4-Fixed ToolWindow |Similar to 3-Fixed Dialog except that the title bar is shorter and the title bar font and Close button are |

| |correspondingly smaller. Use this for floating toolbars. |

|5-Sizable ToolWindow |Similar to a 4-Fixed ToolWindow except that it's sizable by dragging the border. Use this for windows such as the |

| |Visual Basic Properties window. |

The BorderStyle property of a form can be set to one of six different styles. Notice that some styles can look exactly the same as other styles.

Methods are blocks of code designed into a control that tell the control how to do things, such as move to another location on a form. Just as with properties, not all controls have the same methods, although some common methods do exist, as shown in Table 6.3.

TABLE 6.3  Common Methods of Visual Basic Controls

|Method |Use |

|Move |Changes an object's position in response to a code request |

|Drag |Handles the execution of a drag-and-drop operation by the user |

|SetFocus |Gives focus to the object specified in the method call |

|ZOrder |Determines the order in which multiple objects appear onscreen |

Events are what happen in and around your program. For example, when a user clicks a button, many events occur: The mouse button is pressed, the CommandButton in your program is clicked, and then the mouse button is released. These three things correspond to the MouseDown event, the Click event, and the MouseUp event. During this process, the GotFocus event for the CommandButton and the LostFocus event for whichever object previously held the focus also occur.

Again, not all controls have the same events, but some events are shared by many controls (see Table 6.4). These events occur as a result of some specific user action, such as moving the mouse, pressing a key on the keyboard, or clicking a text box. These types of events are user-initiated events and are what you will write code for most often.

[pic]

Using GotFocus and LostFocus

The GotFocus and LostFocus events relate to most other events because they occur whenever a new control becomes active to receive user input. This makes GotFocus and LostFocus useful for data validation, the process of making sure that data is in the proper format for your program. Be careful, though! Improperly coding these two events can cause your program to begin an endless loop, which will cause your program to stop responding.

[pic]

TABLE 6.4  Common Events of Visual Basic Controls

|Event |Occurrence |

|Change |The user modifies text in a combo box or text box. |

|Click |The user clicks the primary mouse button on an object. |

|DblClick |The user double-clicks the primary mouse button on an object. |

|DragDrop |The user drags an object to another location. |

|DragOver |The user drags an object over another control. |

|GotFocus |An object receives focus. |

|KeyDown |The user presses a keyboard key while an object has focus. |

|KeyPress |The user presses and releases a keyboard key while an object has focus. |

|KeyUp |The user releases a keyboard key while an object has focus. |

|Event |Occurrence |

|LostFocus |An object loses focus. |

|MouseDown |The user presses any mouse button while the mouse pointer is over an object. |

|MouseMove |The user moves the mouse pointer over an object. |

|MouseUp |The user releases any mouse button while the mouse pointer is over an object. |

The Relationship Between Properties, Methods, and Events

[pic]

Although properties, methods, and events do different things, it's important to realize that they're often interrelated. For example, if you move a control with the Move method (most likely in response to an event), one or more of the control's position properties (Top, Height, Left, and Width) will change as a result. Because the control's size has changed, the Resize event occurs.

This interdependence means that you can sometimes accomplish the same task multiple ways in your code by manipulating object properties or methods. Consider the following code, which shows two ways to move a CommandButton:

`************************************************

`Move the commandbutton by setting the properties

`************************************************

cmdMove.Left = 100

= 100

`********************************************

`Move the commandbutton by using the Move method

`********************************************

txtMove.Move 100, 100

As another example, you can make a form appear and disappear from the screen by using its Visible property or its Show and Hide methods, as follows:

`***********************************************

` Make the form visible by setting the property

`***********************************************

frmMyForm.Visible=True

`***************************************

` Hide the form by setting the property

`***************************************

frmMyForm.Visible=False

`*********************************************

` Make the form visible by using the Show method

`*********************************************

frmMyForm.Show

`*************************************

` Hide the form by using the Hide method

`*************************************

frmMyForm.Hide

Event Driven Programming

Visual Basic programs are built around events. Events are various things that can happen in a program. this will become clearer when studied in contrast to procedural programming.

In procedural languages, an application is written is executed by checking for the program logically through the program statements, one after another.

For a temporary phase, the control may be transferred to some other point in a program.

While in an event driven application, the program statements are executed only when a particular event calls a specific part of the code that is assigned to the event.

Let us consider a TextBox control and a few of its associated events to understand the concept of event driven programming. The TextBox control supports various events such as Change, Click, MouseMove and many more that will be listed in the Properties dropdown list in the code window for the TextBox control. We will look into a few of them as given below.

• The code entered in the Change event fires when there is a change in the contents of the TextBox

• The Click event fires when the TextBox control is clicked.

• The MouseMove event fires when the mouse is moved over the TextBox

As explained above, several events are associated with different controls and forms, some of the events being common to most of them and few being specific to each control.

The Importance of Event-Driven Programming

• Event-driven programming means that most of the code write will be run as users do things within the program or even when certain things happen in Windows--when events occur.

• Of course, programming this way means that have to know when events occur and have to write code that will make your program do something in response to the event.

• Whenever an event takes place, Windows sends out a message to your program. Your program reads this message, and then runs the code you've attached to the event. If you don't specify code for an event, your program will simply ignore the event.

• Generally, this code is known as a procedure, defined as any block of code that can be called from within your application.

• This code might be used to move objects around on a form, calculate a value from a formula, or write data to a database. No matter the purpose, a procedure always uses this format:

[Public|Private] [Static] Sub|Function|Property _

function_name (arguments) [As Type]

{...Your procedure code...}

End Sub|Function|Property

An event procedure is the place in your project where you put the code that will run when an event occurs. To write an event procedure, you must access the Code window for your object by doing one of the following:

• Double-clicking the object

• Selecting the object with the mouse and pressing F7

• Selecting the object and choosing Code from the View menu

• Selecting the object's form in the Project Explorer, clicking the View Code button, and choosing the object from the Code window

The code write in an event procedure will run whenever the event occurs.

Visual Basic automatically generates an event procedure when select an event in the Code Window. The name event procedures by joining the object's name and the event name with an underscore character (cmdExit_Click()). When the event procedure in this example is run, it will display a dialog when the user clicks the CommandButton named cmdExit.

Using Properties, Methods, and Events in a Sample Program

Properties, methods, and events in an application named MoveIt.

The MoveIt program can be moved around onscreen when users click the buttons on its interface.

MoveIt consists of the form frmMove, which contains four CommandButtons placed in its corners. When you run MoveIt, clicking one of these buttons will move the form to the corresponding corner of the screen. In the center of the form is a label that will provide event notification--in other words, it will report information such as mouse movement and which button has the focus.

Create MoveIt (general steps)

1. Create the graphical user interface (GUI).

2. Program the Form_Load() event procedure.

3. Program the Click() event procedures.

4. Add the event notification.

Creating the Interface

Create MoveIt's GUI

1. Create a new project by choosing New Project from the File menu. Select Standard EXE from the New Project dialog.

2. In the Properties window, change the name of the project's form to frmMove.

3. Add four CommandButtons to frmMove's corners and add a label in the center.

4. In the Properties window, name the label and the four buttons.

5. Now set the BorderStyle property of the form to 1-Fixed Single. This ensures that the form can't be resized while the program is running. Also, set the label's Alignment property to 2-Center and its BorderStyle property to 1-Fixed Single to give the label a finished appearance.

6. Save the form and the project, using friendly names such as frmMove.frm for the form and MoveIt.vbp for the project.

Programming the Form_Load() Event Procedure

Use the Form_Load() event procedure to prepare the form before showing it onscreen when program is run. Use this procedure to

• Set the Caption property of the CommandButtons

• Set the initial text of the label

• Set the form's title bar text

• Set the position of the four CommandButtons, the label, and the form onscreen

Open the Code window for the Form_Load() event procedure by double-clicking anywhere on the form except the buttons, label, or title bar. Then, enter the code in Listing 6.1, being careful to change the names if you named your control differently.

[pic]

LISTING 6.1  The Form_Load() Event Procedure Code for MoveIt

01 `Set the Caption property of the CommandButtons

02 cmdTopLeft.Caption = "Top Left"

03 cmdTopRight.Caption = "Top Right"

04 cmdBottomLeft.Caption = "Bottom Left"

05 cmdBottomRight.Caption = "Bottom Right"

06

07 `Clear the initial text of the label

08 lblNotify.Caption = ""

09

10 `Set the form's title bar text

11 frmMove.Caption = "MoveIt"

12

13 `The rest of the code centers the form on the

14 `screen, sets the position of the four

15 `CommandButtons, and sets the size and

16 `position of the label.

17

18 `Center the form on the screen. This works by

19 `setting the Left side of the form to the center

20 `of the screen, less half the width of the form.

21 `Also, the Top of the form is set to the center

22 `of the screen, less half the height of the form.

23 frmMove.Left = (Screen.Width - frmMove.Width) / 2

24 = (Screen.Height - frmMove.Height) / 2

25

26 `Set the Left edge of the buttons. The 200 setting

27 `for the left buttons sets a space between the edge

28 `of the form and the buttons. The right buttons are

29 `set by subtracting the width of the button from

30 `the width of the form, and subtracting 300 to

31 `set a space between the button and the form edge.

32 cmdTopLeft.Left = 200

33 cmdBottomLeft.Left = 200

34 cmdTopRight.Left = frmMove.Width - cmdTopRight.Width - 300

35 cmdBottomRight.Left = frmMove.Width - cmdBottomRight.Width - 300

36

37 `Set the Top edge of the buttons. This is done

38 `similar to setting the Left edge.

39 = 200

40 = frmMove.Height - cmdBottomLeft.Height - 500

41 = 200

42 = frmMove.Height - cmdBottomRight.Height - 500

43

44 `Set the size of the label

45 lblNotify.Height = 360

46 lblNotify.Width = 3000

47

48 `Center the label within the form. This is done

49 `similar to centering the form.

50 lblNotify.Left = (frmMove.Width - lblNotify.Width) / 2

51 = (frmMove.Height - lblNotify.Height) / 2 - 200

Setting these starting values is called initialization.

Programming the Click() Event

Use the Click() event procedure to move the form around the screen. To do so, double-click a CommandButton to view the Code window. Then, enter that part of the code from Listing 6.2 that applies to that CommandButton.

[pic]

LISTING 6.2  The Click() Event Procedures for the CommandButtons

01 Private Sub cmdBottomLeft_Click()

02

03 `Set the value of the form's TOP property

04 `to the bottom of the screen but bring

05 `it up the height of the screen so that the

06 `bottom of the form is on the bottom of

07 `the screen

08 = Screen.Height - frmMove.Height

09

10 `Set the value of the form's LEFT property

11 `to the far left of the screen.

12 frmMove.Left = 0

13

14 End Sub

15

16 Private Sub cmdBottomRight_Click()

17

18 `Set the value for the form's TOP property to

19 `the bottom of the screen, but bring the TOP

20 `up the HEIGHT of the form so that the bottom

21 `of the form is on the bottom of the screen.

22 = Screen.Height - frmMove.Height

23

24 `Set the value of the form's LEFT property to

25 `the right of the screen but bring it across

26 `the screen the width of the form so that the

27 `right side of the form is on the right

28 `side of the screen

29 frmMove.Left = Screen.Width - frmMove.Width

30

31 End Sub

32

33 Private Sub cmdTopLeft_Click()

34

35 `Set the value of the form's TOP property

36 `to the top of the screen.

37 = 0

38

39 `Set the value of the form's LEFT property

40 `to the left of the screen.

41 frmMove.Left = 0

42

43 End Sub

44

45 Private Sub cmdTopRight_Click()

46

47 `Set the value of the form's TOP property

48 `to the top of the screen.

49 = 0

50

51 `Set the value of the form's LEFT property to

52 `the right of the screen but bring it back across

53 `the screen the width of the form, so that the

54 `right side of the form is on the right

55 `side of the screen

56 frmMove.Left = Screen.Width - frmMove.Width

57

58 End Sub

Moving the form to the top or left of the screen is easy--set the Top or Left property of the form to zero. This always corresponds to the top or left of your monitor, respectively.

Lining up the form on the right side or bottom of the screen is a little harder because right and bottom properties don't exist. To place a form on the right side of the screen, must set the Left property of the form to the Width property of the Screen object, minus the Width of the form (because the Width of the screen would be the right property of the screen, if the right property existed).

A similar technique is used to determine the bottom of the screen. To set the form's Top property equal to the screen's Height property, wouldn't see the form because it would be just below the bottom of the screen. To set the bottom of the form to the bottom of the screen, you subtract the value of the form's Height property from the value of the screen's Height property. This raises the form so that you can see it.

Adding Event Notification

To finish MoveIt, let's add some code that will tell when certain events occur for the form and the CommandButtons. When users press or release the mouse button over the form, the text in lblNotify will change to reflect the state of the button. Also, when users use the Tab key or the mouse button to move from one CommandButton to another (which changes the focus from one button to the next), the text in lblNotify will change. Doing this requires to write code in three different event procedures: the MouseUp and MouseDown event procedures for the form and the GotFocus event procedure for each CommandButton.

Be careful when placing a form on the right side or bottom of the screen; otherwise, you might place it offscreen.

Enter the code from Listing 6.3 into the MouseUp and MouseDown event procedures for frmMain. To do this, open the Code window for the MouseDown event procedure by double-clicking the form and selecting MouseDown from the event procedures drop-down list .

LISTING 6.3  Code for Reporting When Users Click and Release the Mouse Button

01 Private Sub Form_MouseDown(Button As Integer, _

Shift As Integer, X As Single, Y As Single)

02

03 lblNotify.Caption = "MouseDown Event"

04

05 End Sub

06

07 Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

08

09 lblNotify.Caption = "MouseUp Event"

10

11 End Sub

When the program runs, if your mouse is over the form (not the CommandButtons or the label) and you click the mouse button, the text MouseDown Event appears in lblNotify. When you release your mouse button, the text MouseUp Event appears.

Last, add the code that will report which CommandButton has the focus. Enter the code from Listing 6.4 into the GotFocus event procedures for each CommandButton. Do this by double-clicking one of the CommandButtons and selecting the GotFocus event procedure (notice that Visual Basic selects the Click event by default). Repeat this procedure for each CommandButton.

LISTING 6.4  Code for Reporting Which CommandButton Has the Focus

01 Private Sub cmdBottomLeft_GotFocus()

02

03 lblNotify.Caption = "cmdBottomLeft has the Focus"

04

05 End Sub

06

07 Private Sub cmdBottomRight_GotFocus()

08

09 lblNotify.Caption = "cmdBottomRight has the Focus"

10

11 End Sub

12

13 Private Sub cmdTopLeft_GotFocus()

14

15 lblNotify.Caption = "cmdTopLeft has the Focus"

16

17 End Sub

18

19 Private Sub cmdTopRight_GotFocus()

20

21 lblNotify.Caption = "cmdTopRight has the Focus"

22

23 End Sub

Working with Forms in Visual Basic

The main characteristic of a Form is the title bar on which the Form's caption is displayed. On the left end of the title bar is the Control Menu icon. Clicking this icon opens the Control Menu. Maximize, Minimize and Close buttons can be found on the right side of the Form. Clicking on these buttons performs the associated function.

The following figure illustrates the appearance of a Form

[pic]

The control menu contains the following commands :

• Restore : Restores a maximized Form to the size it was before it was maximized; available only if the Form has been maximized.

• Move : Lets the user moves the Form around with the mouse

• Size : Lets the user resizes the control with the mouse

• Minimize: Minimizes the Form

• Maximize : Maximizes the Form

• Close : Closes the Form

Setting the Start-Up Form

A typical application has more than a single Form. When an application runs the main Form is loaded. By setting the Project properties you can control which Form is to be displayed in the Start-Up of the application. Following figure illustrates the Project property window.

[pic]

By default, Visual Basic suggests the name of the first Form created when the project started.

Loading and Unloading Forms

In order to load and unload the forms, Load and Unload statements are used. The Load statement has the following syntax :

Load FormName

And the Unload statement has the following syntax :

Unload FormName

The FormName variable is the name of the Form to be loaded or unloaded. Unlike the Show method which cares of both loading and displaying the Form, the load statement doesn't show the Form. You have to call the Form's Show method to display it on the desktop.

Showing and Hiding Forms

Show method is used to Show a Form. If the Form is loaded but invisible, the Show method is used to bring the Form on Top every other window. If the Form is not loaded, the Show method loads it and then displays it.

Syntax of the Show method of the Form

FormName.Show mode

The FormName variable is the Form's name, and the optional argument mode determines whether the Form will be Modal or not. It can have one of the following syntax :

* 0-Modeless (default)

* 1-Modal

Modeless Forms are the normal Forms. Modeless Forms interact with the user and the user allowed to switch to any other Form of the application. If you do not specify the optional mode argument, by default the mode is set to modeless.

The Modal Forms takes the total control of the application where user cannot switch to any other Forms in the application unless the Form is closed. A modal Form, thus, must have a Close button or some means to close the Form in order to return to the Form where the Modal Form was loaded.

Hiding Forms

The Hide method is used to hide a Form. The following is the syntax of the Hide Method.

FormName.Hide

To hide a Form from within its own code, the following code can be used.

Me.Hide

Understand that the Forms that are hidden are not unloaded ; they remains in the memory and can be displayed instantly with the Show Method. When a Form is hidden, you can still access its properties and code. For instance, you can change the settings of its Control Properties or call any Public functions in the Form.

The following is an example illustrates the Show method and Mode statement

* Open a new Project and save the Project

Design the application as shown below

|Object |Property |Setting |

|Form |Caption |Form1 |

| |Name |frm1 |

|Form |Caption |Form2 |

| |Name |frm2 |

|Form |Caption |Form3 |

| |Name |frm3 |

|Label |Caption |Click on a button to |

| |Name |display a Form |

| | |Label1 |

[pic]

The following code is typed in the Click event of the command buttons

[pic]

Run the application. Clicking on the buttons will display the Forms respectively.

Finding out the difference between Unload and Hide method

To know what the difference is between Unload and Hide methods we will do an example. Open a new project and save the project. Draw two buttons on the form and name those as shown above.

[pic]

In the click event of the Hide button Following code is entered.

Me.Hide

In the click event of the Unload button following code is entered.

Unload Me

Save the project and run the application. Once you click on Hide button you can note that the Form is invisible but the application is still running. But when you click on Unload button you can see that the application is terminated.

Variables

Variables are the memory locations which are used to store values temporarily. A defined naming strategy has to be followed while naming a variable. A variable name must begin with an alphabet letter and should not exceed 255 characters. It must be unique within the same scope. It should not contain any special character like %, &, !, #, @ or $.

There are many ways of declaring variables in Visual Basic. Depending on where the variables are declared and how they are declared, we can determine how they can be used by our application. The different ways of declaring variables in Visual Basic are listed below and elucidated in this section.

Syntax

Dim variable [As Type]

Dim I as integer

Dim intInterestRate As Integer = 10

Scope of variables

A variable is scoped to a procedure-level (local) or module-level variable depending on how it is declared. The scope of a variable, procedure or object determines which part of the code in our application are aware of the variable's existence. A variable is declared in general declaration section of e Form, and hence is available to all the procedures. Local variables are recognized only in the procedure in which they are declared. They can be declared with Dim and Static keywords. If we want a variable to be available to all of the procedures within the same module, or to all the procedures in an application, a variable is declared with broader scope.

Local Variables

A local variable is one that is declared inside a procedure. This variable is only available to the code inside the procedure and can be declared using the Dim statements as given below.

Dim sum As Integer

The local variables exist as long as the procedure in which they are declared, is executing. Once a procedure is executed, the values of its local variables are lost and the memory used by these variables is freed and can be reclaimed. Variables that are declared with keyword Dim exist only as long as the procedure is being executed.

Static Variables

Static variables are not reinitialized each time Visual Invokes a procedure and therefore retains or preserves value even when a procedure ends. In case we need to keep track of the number of times a command button in an application is clicked, a static counter variable has to be declared. These static variables are also ideal for making controls alternately visible or invisible. A static variable is declared as given below.

Static intPermanent As Integer

Variables have a lifetime in addition to scope. The values in a module-level and public variables are preserved for the lifetime of an application whereas local variables declared with Dim exist only while the procedure in which they are declared is still being executed. The value of a local variable can be preserved using the Static keyword. The follwoing procedure calculates the running total by adding new values to the previous values stored in the static variable value.

Function RunningTotal ( )

Static Accumulate

Accumulate = Accumulate + num

RunningTotal = Accumulate

End Function

If the variable Accumulate was declared with Dim instead of static, the previously accumulated values would not be preserved accross calls to the procedure, and the procedure would return the same value with which it was called. To make all variables in a procedure static, the Static keyword is placed at the beginning of the procedure heading as given in the below statement.

Static Function RunningTotal ( )

Example

The following is an example of an event procedure for a CommandButton that counts and displays the number of clicks made.

Private Sub Command1_Click ( )

Static Counter As Integer

Counter = Counter + 1

Print Counter

End Sub

The first time we click the CommandButton, the Counter starts with its default value of zero. Visual Basic then adds 1 to it and prints the result.

Module Levele Variables

A module level variable is available to all the procedures in the module. They are declared using the Public or the Private keyword. If you declare a variable using a Private or a Dim statement in the declaration section of a module—a standard BAS module, a form module, a class module, and so on—you're creating a private module-level variable. Such variables are visible only from within the module they belong to and can't be accessed from the outside. In general, these variables are useful for sharing data among procedures in the same module:

' In the declarative section of any module

Private LoginTime As Date ' A private module-level variable

Dim LoginPassword As String ' Another private module-level variable

You can also use the Public attribute for module-level variables, for all module types except BAS modules. (Public variables in BAS modules are global variables.) In this case, you're creating a strange beast: a Public module-level variable that can be accessed by all procedures in the module to share data and that also can be accessed from outside the module. In this case, however, it's more appropriate to describe such a variable as a property:

' In the declarative section of Form1 module

Public CustomerName As String ' A Public property

You can access a module property as a regular variable from inside the module and as a custom property from the outside:

' From outside Form1 module...

Form1.CustomerName = "John Smith"

The lifetime of a module-level variable coincides with the lifetime of the module itself. Private variables in standard BAS modules live for the entire life of the application, even if they can be accessed only while Visual Basic is executing code in that module. Variables in form and class modules exist only when that module is loaded in memory. In other words, while a form is active (but not necessarily visible to the user) all its variables take some memory, and this memory is released only when the form is completely unloaded from memory. The next time the form is re-created, Visual Basic reallocates memory for all variables and resets them to their default values (0 for numeric values, "" for strings, Nothing for object variables).

Public vs Local Variables

A variable can have the same name and different scope. For example, we can have a public variable named R and within a procedure we can declare a local variable R. References to the name R within the procedure would access the local variable and references to R outside the procedure would access the public variable.

Constants

Constants are named storage locations in memory, the value of which does not change during program Execution. They remain the same throughout the program execution. When the user wants to use a value that never changes, a constant can be declared and created. The Const statement is used to create a constant. Constants can be declared in local, form, module or global scope and can be public or private as for variables. Constants can be declared as illustrated below.

Public Const gravityconstant As Single = 9.81

Compile-time and Run-time Constants

A compile-time constant is computed at the time the code is compiled, while a run-time constant can only be computed while the application is running. A compile-time constant will have the same value each time an application runs, while a run-time constant may change each time. Compile-time constants are required for cases such as array bounds, case expressions, or enumerator initializers.

You use the Const statement to declare a constant and set its value. By declaring a constant, you assign a meaningful name to a value. Once a constant is declared, it cannot be modified or assigned a new value.

Write a declaration that includes an access specifier, the Const keyword, and an expression, as in the following examples:

Public Const DaysInYear = 365

Private Const WorkDays = 250

DATATYPES

5.1 Visual Basic Data Types

Visual Basic classifies the information mentioned above into two major data types, they are the numeric data types and the non-numeric data types.

5.1.1 Numeric Data Types

Numeric data types are types of data that consist of numbers, which can be computed mathematically with various standard operators such as add, minus, multiply, divide and more. Examples of numeric data types are examination marks, height, weight, the number of students in a class, share values, price of goods, monthly bills, fees and others. In Visual Basic, numeric data are divided into 7 types, depending on the range of values they can store. Calculations that only involve round figures or data that does not need precision can use Integer or Long integer in the computation. Programs that require high precision calculation need to use Single and Double decision data types, they are also called floating point numbers. For currency calculation , you can use the currency data types. Lastly, if even more precision is required to perform calculations that involve a many decimal points, we can use the decimal data types. These data types summarized in Table 5.1

Table 5.1: Numeric Data Types

Type Storage Range of Values

Byte 1 byte 0 to 255

Integer 2 bytes -32,768 to 32,767

Long 4 bytes -2,147,483,648 to 2,147,483,648

Single 4 bytes -3.402823E+38 to -1.401298E-45 for negative values

1.401298E-45 to 3.402823E+38 for positive values.

Double 8 bytes

-1.79769313486232e+308 to -4.94065645841247E-324 for negative values

4.94065645841247E-324 to 1.79769313486232e+308 for positive values.

Currency 8 bytes -922,337,203,685,477.5808 to 922,337,203,685,477.5807

Decimal 12 bytes +/- 79,228,162,514,264,337,593,543,950,335 if no decimal is use

+/- 7.9228162514264337593543950335 (28 decimal places).

5.1.2 Non-numeric Data Types

Nonnumeric data types are data that cannot be manipulated mathematically using standard arithmetic operators. The non-numeric data comprises text or string data types, the Date data types, the Boolean data types that store only two values (true or false), Object data type and Variant data type .They are summarized in Table 5.2

Table 5.2: Nonnumeric Data Types

Data Type Storage Range

String(fixed length) Length of string 1 to 65,400 characters

String(variable length) Length + 10 bytes 0 to 2 billion characters

Date 8 bytes January 1, 100 to December 31, 9999

Boolean 2 bytes True or False

Object 4 bytes Any embedded object

Variant(numeric) 16 bytes Any value as large as Double

Variant(text) Length+22 bytes Same as variable-length string

5.1.3 Suffixes for Literals

Literals are values that you assign to data. In some cases, we need to add a suffix behind a literal so that VB can handle the calculation more accurately. For example, we can use num=1.3089# for a Double type data. Some of the suffixes are displayed in Table 5.3.

Table 5.3

Suffix Data Type

& Long

! Single

# Double

@ Currency

In addition, we need to enclose string literals within two quotations and date and time literals within two # sign. Strings can contain any characters, including numbers. The following are few examples:

memberName="Turban, John."

TelNumber="1800-900-888-777"

LastDay=#31-Dec-00#

ExpTime=#12:00 am#

Unit – III

Functions – Procedures – Control Structure : If - Switch – Select – For – While – Do While - Arrays – User Defined Data Types – Data Type Conversions - Operators – String Functions – Date and Time Functions.

Procedures in Visual Basic

• Visual Basic offers different types of procedures to execute small sections of coding in applications.

• The various procedures are elucidated in details in this section. Visual Basic programs can be broken into smaller logical components called Procedures.

• Procedures are useful for condensing repeated operations such as the frequently used calculations, text and control manipulation etc.

The benefits of using procedures in programming are:

• It is easier to debug a program a program with procedures, which breaks a program into discrete logical limits.

• Procedures used in one program can act as building blocks for other programs with slight modifications.

• A Procedure can be Sub, Function or Property Procedure.

Sub Procedures

A sub procedure can be placed in standard, class and form modules. Each time the procedure is called, the statements between Sub and End Sub are executed. The syntax for a sub procedure is as follows:

[Private | Public] [Static] Sub Procedurename [( arglist)]

[ statements]

End Sub

arglist is a list of argument names separated by commas. Each argument acts like a variable in the procedure. There are two types of Sub Procedures namely general procedures and event procedures.

Event Procedures

An event procedure is a procedure block that contains the control's actual name, an underscore(_), and the event name. The following syntax represents the event procedure for a Form_Load event.

Private Sub Form_Load()

....statement block..

End Sub

Event Procedures acquire the declarations as Private by default.

Function Procedures

• Functions are like sub procedures, except they return a value to the calling procedure.

• They are especially useful for taking one or more pieces of data, called arguments and performing some tasks with them.

• Then the functions returns a value that indicates the results of the tasks complete within the function.

• The following function procedure calculates the third side or hypotenuse of a right triangle, where A and B are the other two sides.

• It takes two arguments A and B (of data type Double) and finally returns the results.

Function Hypotenuse (A As Double, B As Double) As Double

Hypotenuse = sqr (A^2 + B^2)

End Function

The above function procedure is written in the general declarations section of the Code window. A function can also be written by selecting the Add Procedure dialog box from the Tools menu and by choosing the required scope and type.

Property Procedures

A property procedure is used to create and manipulate custom properties. It is used to create read only properties for Forms, Standard modules and Class modules.Visual Basic provides three kind of property procedures-Property Let procedure that sets the value of a property, Property Get procedure that returns the value of a property, and Property Set procedure that sets the references to an object.

Defining procedures

An example function definition:

Public Function Sum(ByRef Number1 As Double, ByRef Number2 As Double) As Double

'Return the result by writing it to a variable having the same name as the function

Sum = Number1 + Number2

End Function

An example subroutine definition:

Public Sub Tell(ByVal MyString1 as String, ByVal MyString2 as String)

MsgBox MyString1 & MyString2

End Sub

Note the following:

The arguments to the function are declared as ByRef which requires the compiler to make sure that only arguments of the specified type are used, in this case Double.

The function returns a value by assigning it to the function name as though the function were a variable. This contrasts with the use of the keyword return in many other languages.

Calling procedures:

You can use or call the two procedures defined in the previous sections as follows:

'On the next line, argument order matters

Tell "Hello there.", ""

'On the next line, names of arguments are used and argument order does not matter.

Tell MyString1:="Hello there,", MyString2:=" again."

'Tell ("Hello there.","") -- syntax error

MySum = Sum(123.456, 234)

MySum2 = Sum(Number2:=8, Number1:=6)

'MySum3 = Sum Number2:=8, Number1:=6 -- syntax error

Note the following:

The arguments (argument list) passed to a function must be enclosed in round brackets, whereas those supplied to a subroutine need not.

Control Statements:

Control Statements are used to control the flow of program's execution. Visual Basic supports control structures such as if... Then, if...Then ...Else, Select...Case, and Loop structures such as Do While...Loop, While...Wend, For...Next etc method.

If...Then selection structure:

The If...Then selection structure performs an indicated action only when the condition is True; otherwise the action is skipped.

Syntax of the If...Then selection

If Then

statement

End If

e.g.: If average>75 Then

txtGrade.Text = "A"

End If

If...Then...Else selection structure:

The If...Then...Else selection structure allows the programmer to specify that a different action is to be performed when the condition is True than when the condition is False.

Syntax of the If...Then...Else selection

If Then

statements

Else

statements

End If

e.g.: If average>50 Then

txtGrade.Text = "Pass"

Else

txtGrade.Text = "Fail"

End If

Nested If...Then...Else selection structure:

Nested If...Then...Else selection structures test for multiple cases by placing If...Then...Else selection structures inside If...Then...Else structures.

Syntax of the Nested If...Then...Else selection structure

You can use Nested If either of the methods as shown above

Method 1:

If < condition 1 > Then

statements

ElseIf < condition 2 > Then

statements

ElseIf < condition 3 > Then

statements

Else

Statements

End If

Method 2:

If < condition 1 > Then

statements

Else

If < condition 2 > Then

statements

Else

If < condition 3 > Then

statements

Else

Statements

End If

End If

End If

e.g.: Assume you have to find the grade using nested if and display in a text box

If average > 75 Then

txtGrade.Text = "A"

ElseIf average > 65 Then

txtGrade.Text = "B"

ElseIf average > 55 Then

txtGrade.text = "C"

ElseIf average > 45 Then

txtGrade.Text = "S"

Else

txtGrade.Text = "F"

End If

Select...Case selection structure:

Select...Case structure is an alternative to If...Then...ElseIf for selectively executing a single block of statements from among multiple block of statements. Select...case is more convenient to use than the If...Else...End If. The following program block illustrate the working of Select...Case.

Syntax of the Select...Case selection structure:

Select Case Index

Case 0

Statements

Case 1

Statements

End Select

e.g.: Assume you have to find the grade using select...case and display in the text box

Dim average as Integer

average = txtAverage.Text

Select Case average

Case 100 To 75

txtGrade.Text ="A"

Case 74 To 65

txtGrade.Text ="B"

Case 64 To 55

txtGrade.Text ="C"

Case 54 To 45

txtGrade.Text ="S"

Case 44 To 0

txtGrade.Text ="F"

Case Else

MsgBox "Invalid average marks"

End Select

LOOPS (REPETITION STRUCTURES):

The For...Next Loop:

` The For...Next Loop is another way to make loops in Visual Basic. For...Next repetition structure handles all the details of counter-controlled repetition. The following loop counts the numbers from 1 to 100:

Dim x As Integer

For x = 1 To 50

Print x

Next

In order to count the numbers from 1 yo 50 in steps of 2, the following loop can be used

For x = 1 To 50 Step 2

Print x

Next

The following loop counts numbers as 1, 3, 5, 7..etc

The above coding will display numbers vertically on the form. In order to display numbers horizontally the following method can be used.

For x = 1 To 50

Print x & Space$ (2);

Next

To increase the space between the numbers increase the value inside the brackets after the & Space$.

Following example is a For...Next repetition structure which is with the If condition used.

Dim number As Integer

For number = 1 To 10

If number = 4 Then

Print "This is number 4"

Else

Print number

End If

Next

In the output instead of number 4 you will get the "This is number 4".

While Repetition Structure:

A repetition structure allows the programmer to specify that an action be repeated a number

of times, depending on the value of a condition. Visual Basic .NET provides seven repetition

structures—one of which is the While repetition structure.

As an example of a While structure, consider a program segment designed to find the

first power of two larger than 1000. Suppose Integer variable product contains the

value 2. When the following While structure finishes executing, product contains the result:

Dim product As Integer = 2

While product Delete( );

}

Data Report:

A Data Report is similar to a VB form in that it has a visual designer and a code module. Using the visual designer, you can divide the report into two or more sections, each with its own headings. Each section can contain controls to display the report details. The design of the details sections is simplified by drag-and-drop functionality. The available controls are distinct from VB controls but have similar functionality.

Data Environment:

Data Environment object is created and managed using Data Environment designer. A Data Environment object can accomplish any of the following tasks.

• Can contain connection and command objects

• Can establish relationship between command object to represent hierarchies

• Can group data and get aggregates

• Allows fields to be dragged and dropped on to a Data Report, for report, and a Form for data entry screen

• Can work as source for Databound control such as DataCombo controls and Hierarchical Flexgrid control.

In order to work with Data Environment object, you have to add Data Environment Designer to your project. Data Environment Designer allows programmer to accomplish any of the tasks mentioned above. Data Environment Designer is invoked when you double click on Data Environment object in Project Explorer.

To add Data Environment object to the project:

1. Select Project-> Add Data Environment. If Add Data Environment option is not found then select More ActiveX Designers and then select Data Environment.

Note: Visual Basic adds Data Environment Designer to your project and also creates a connection object.

Data Environment Designer:

Working with Connection Object:

A Connection object represents a connection to a remote database that is used as a data source.

Whenever you create a Data Environment object a Connection object is added to Data Environment object. But that Connection object is not connected to any database. So first we have to establish a connection with the Connection object. Now, let us see how to connect to database through Connection object. 

To connect to Biblio.mdb using connection object:

1. Select Connection object (Connection1) and click on right button.

2. From popup menu select Properties option

Data Environment designer displays Data Link properties dialog.

3. Select the required OLEDB provider (Microsoft Jet 3.51 OLE DB Provider)

4. Select Connection tab and select the name of the database ( BIBLIO.MDB)

5. Click on Ok

To rename connection object:

1. Invoke popup menu by click on Connection object with right button.

2. Select Rename option.

3. Enter new name and press enter key to confirm it.

Creating Command Object

Command objects define specific detailed information about what data is retrieved from a database connection. Command objects can be based on either a database object (such as a table, view, stored procedure or synonym) or a Structured Query Language (SQL) query.

After connection is established using Connection object, now we have to create a command object to access the data of the database. A connection object can contain any number of command objects. In fact, a command object can contain another command object, which is called as child command object.

To create command object to get data from Authors table:

1. Invoke popup menu of Connection object and select Add Command option

Data Environment Designer creates a command object with name Command1.

2. Invoke Popup menu of command object by clicking on right button and select Properties option.

Properties dialog is displayed 

3. Change the Name of the command object to Authors

4. Select Table as Database Object

5. Invoke the list of tables by clicking on down arrow of Object Name drop down and select Authors as the name of the table.

6. For the time being, ignore remaining tabs and click on OK.

Properties of Command object:

A command object is created with the default name (command1). If you expand the command object by clicking on + sign, you get the columns of AUTHORS table. 

Data Report Designer:

[pic]

The Data Report designer is a versatile data report generator that features the ability to created banded hierarchical reports. Used in conjunction with a data source such as the Data Environment designer, you can create reports from several different relational tables

• Automatically create reports that are exported in HTML format for instant distribution on the Internet.

• Create reports that show the sums of transactions occurring on a daily basis.

[pic]

Sections of the Data Report Designer:

The default Data Report designer contains these Sections:

• Report Header—contains the text that appears at the very beginning of a report, such as the report title, author, or database name. If you want the Report Header to be the first page in the report, set its ForcePageBreak property to rptPageBreakAfter.

• Page Header—contains information that goes at the top of every page, such as the report's title.

• Group Header/Footer—contains a "repeating" section of the data report. Each group header is matched with a group footer. The header and footer pair are associated with a single Command object in the Data Environment designer.

• Details—contains the innermost "repeating" part (the records) of the report. The details section is associated with the lowest-level Command object in a Data Environment hierarchy.

• Page Footer—contains the information that goes at the bottom of every page, such as the page number.

• Report Footer—contains the text that appears at the very end of the report, such as summary information, or an address or contact name. The Report Footer appears between the last Page Header and Page Footer.

Data Report Designer Features:

The Data Report designer has several features:

1. Drag-and-Drop Functionality for Fields—Drag fields from the Microsoft Data Environment designer to the Data Report designer. When you do this, Visual Basic automatically creates a text box control on the data report and sets the DataMember and DataField properties of the dropped field. You can also drag a Command object from the Data Environment designer to the Data Report designer. In that case, for each of the fields contained by the Command object, a text box control will be created on the data report; the DataMember and DataField property for each text box will be set to the appropriate values.

2. Toolbox Controls—The Data Report designer features its own set of controls. When a Data Report designer is added to a project, the controls are automatically created on a new Toolbox tab named DataReport. Most of the controls are functionally identical to Visual Basic intrinsic controls, and include a Label, Shape, Image, TextBox, and Line control. The sixth control, the Function control, automatically generates one of four kinds of information: Sum, Average, Minimum, or Maximum. For more information about the Function control, see "Adding a Function Control to the Data Report."

3. Print Preview—Preview the report by using the Show method. The data report is then generated and displayed in its own window.

4. Print Reports—Print a report programmatically by calling the PrintReport method. When the data report is in preview mode, users can also print by clicking the printer icon on the toolbar.

5. File Export—Export the data report information using the ExportReport method. Formats for export include HTML and text.

6. Export Templates—You can create a collection of file templates to be used with the ExportReport method. This is useful for exporting reports in a variety of formats, each tailored to the report type.

7. Asynchonous Operation—The DataReport object's PrintReport and ExportReport methods are asynchronous operations. Using the ProcessingTimeout event, you can monitor the state of these operations and cancel any that are taking too long.

Data Report Controls:

When a new Data Report designer is added to a project, the following controls are automatically placed in the Toolbox tab named DataReport:

• TextBox Control (RptTextBox)—allows you to format text, or assign a DataFormat.

• Label Control (RptLabel)—allows you to place labels on the report to identify fields or sections.

• Image Control (RptImage)—enables you to place graphics on your report. Note that this control cannot be bound to a data field.

• Line Control (RptLine)—lets you draw rules on the report to further distinguish sections.

• Shape Control (RptShape)—enables you to place rectangles, triangles, or circles (and ovals) on a report.

• Function Control (RptFunction)—a special text box that calculates values as the report is generated.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download

To fulfill the demand for quickly locating and searching documents.

It is intelligent file search solution for home and business.

Literature Lottery

Related searches