Visual Basic Theory(Components )

Components of Visual Basic 6.0 



 Application
An application is a collection of objects that work together to accomplish  something useful. In VB the application is called a Project.

Object
An object is a piece of software that has properties and functions that can  be manipulated. A window is an object.

Event-driven
An event is something that happens - the user clicks on a button, a form  is opened, and the result of a calculation is too large.

Advantages of VB
  1. VB applications are event-driven
  2. VB supports the principals of objected-oriented design
  3. VB is a complete windows application development  system
  4. VB uses ActiveX controls, dynamically linked libraries  (DDL) and add-ins.
Different type of projects
Standard
ActiveX EXE
ActiveX DLL
ActiveX Control  Data Project  IIS Application
ActiveX Document DLL
ActiveX Document EXE
DHTML Application

Uses of Projects

Standard : this project contains the standard set of controls and is used  to create a basic windows application or to start a large application  project.

ActiveX EXE : This project helps you create an ActiveX executable  component that can be executed from other applications.

ActiveX DLL : An ActiveX DLL is used to contain controls and class  code that can be used in other projects.

ActiveX Control : This enables you to create a custom ActiveX control.


Data Project : This project starts with database components already  added to project file.

IIS Application : This project is used to create an Internet Application.

ActiveX Document DLL : This is used to by VB applications that will be  installed and executed from the Internet.

ActiveX Document EXE : This project is used to create an Internet-  based VB application


DHTML Application : This project creates a Web/HTML based  application that can be executed only in a web browser.



Different Components of a  Project

§  Form (.frm)           
§  Standard(.bas)
§  Resource(.res)
§  ActiveX documents(.doc)
§  User controls(.ctl) and Property Pages(.pag)
§  ActiveX Controls (.ocx)
§  Class (.cls)           
§  ActiveX Designers(.dsr)

components:-

                         
The Visual Basic development environment contains these programming tools and windows, with which you construct your Visual Basic programs:

  • Menu bar
  • Toolbars
  • Visual Basic toolbox
  • Form window
  • Properties window
  • Project Explorer
  • Immediate window
  • Form Layout window

1.    Menu bar
Located at the top of the screen, the menu bar  provides access to the commands that control the  Visual Basic programming environment.
Menus and commands work according to standard  conventions used in all Windows-based programs.

2. Toolbars
 Located below the menu bar, toolbars are collections  of buttons that serve as shortcuts for executing  commands and controlling the Visual Basic development environment.

You can open special-purpose toolbars by using the  View menu Toolbars command 


3. Windows taskbar 

                                          This taskbar is located along the bottom of the screen.
You can use the taskbar to switch between Visual  Basic forms as your program runs and to activate  other Windowsbased programs.


Toolbox control
§  You use special tools, called controls, to add  elements of a program user interface to a form.
  • These resources in the toolbox, which is  typically located along the left side of the  screen.
  • (If the toolbox is not open, display it by using  the Toolbox command on the View menu.)


Form Windows
When you start Visual Basic, a default form  (Form1) with a standard grid (a window  consisting of regularly spaced dots) appears in  a pane called the Form window.
You can use the Form window grid to create  the user interface and to line up interface  elements.

Building Interface Elements

To build the interface elements, you click an interface  control in the Visual Basic toolbox, and then you draw  the user interface element on your form by using the  mouse.
This process is usually a simple matter of clicking to  position one corner of the element and then dragging to  create a rectangle the size you want.
After you create the element — say, a text box — you  can refine it by setting properties for the element.
In a text box, for example, you can set properties to  make the text boldface, italic, or underlined.

Properties window
 With the Properties window, you change the  characteristics (property settings) of the user interface  elements on a form
Properties Window Elements

The Properties window contains the following  elements:

A drop-down list box at the top of the window, from  which you select the object whose properties you  want to view or set.

Two tabs, which list the properties either  alphabetically or by category.
A description pane that shows the name of the  selected property and a short description of it.

Project window
A Visual Basic program consists of several files that  are linked together to make the program run.
The Visual Basic 6.0 development environment  includes a Project window to help you switch back  and forth between these components as you work on  a project

Project Window Components
The Project window lists all the files used in the  programming process and provides access to them  with two special buttons: View Code and View  Object.

§  Code window
§  This computing logic is created using program  statements — keywords,identifiers, and  arguments — that clearly spell out what the  program should do each step of the way.
§  You enter program statements in the Code  window, a special text editing window designed  specifically for Visual Basic program code.
§  You can display the Code window in either of two  ways:
§  By clicking View Code in the Project window.
§  By clicking the View menu Code command.

Form Layout Window
  • The Form Layout window is a visual design tool.
  • With it, you can control the placement of the forms in  the Windows environment when they are executed.
  • When you have more than one form in your program,  the Form Layout window is especially useful — you  can arrange the forms onscreen exactly the way you  want.
  • To position a form in the Form Layout window,  simply drag the miniature form to the desired location  in the window.

 The exact size and shape of the windows depends on how your system has been configured. In Visual Basic 6.0, you can align and attach (dock) the windows to make all the elements of the programming system visible and accessible. You’ll learn how to customize your development environment in Moving, Docking, and Resizing Windows.



Loading and Running a Program

Before you can work with a Visual Basic program, you need to load the program into memory, just as you would load a word processing document in a word processor for editing.

To load a Visual Basic program into memory and run it

  1. On the File menu, click Open Project. The Open Project dialog box appears. With this dialog box, you can open any existing Visual Basic program on your hard disk, attached network drive, CD-ROM, or floppy disk.
  2. If necessary, use the Look In drop-down list box and the Up One Level button to locate the program you want to load. Then, double-click the program name. The project file loads the Visual Basic user interface form, properties, and program code. (Visual Basic project files are distinguished by the .VBP file name extension.)
  3. If the program user interface does not appear, open the Forms folder in the Project window, select the first form, and then click View Object in the Project window. This is an optional but useful step, especially if you want to look at the program user interface in the Form window before you run it.
  4. On the Visual Basic Standard toolbar, click Start to run the program. The toolbox and several of the other windows disappear, and the Visual Basic program starts to run.
  5. On the toolbar, click End when you want to exit the program.
See below to view an illustration of the standard contents of the toolbox.


Form Window

When you start Visual Basic, a default form (Form1) with a standard grid (a window consisting of regularly spaced dots) appears in a pane called the Form window. You can use the Form window grid to create the user interface and to line up interface elements.



Building Interface Elements
To build the interface elements, you click an interface control in the Visual Basic toolbox, and then you draw the user interface element on your form by using the mouse. This process is usually a simple matter of clicking to position one corner of the element and then dragging to create a rectangle the size you want. After you create the element — say, a text box — you can refine it by setting properties for the element. In a text box, for example, you can set properties to make the text boldface, italic, or underlined.

Adjusting Form Size
You can adjust the size of the form by using the mouse — the form can take up part or the entire screen.

Controlling Form Placement
To control the placement of the form when you run the program, adjust the placement of the form in the Form Layout window.



Properties Window

With the Properties window, you change the characteristics (property settings) of the user interface elements on a form. A property setting is a characteristic of a user interface object. For example, you can change the text displayed by a text box control to a different font, point size, or alignment. (With Visual Basic, you can display text in any font installed on your system, just as you can in Microsoft Excel or Microsoft Word.)



Displaying the Properties Window
To display the Properties window, click the Properties Window button on the toolbar. If the window is currently docked, you can enlarge it by double-clicking the title bar. To redock the Properties window, double-click its title bar again.

Properties Window Elements
The Properties window contains the following elements:
  • A drop-down list box at the top of the window, from which you select the object whose properties you want to view or set.
  • Two tabs, which list the properties either alphabetically or by category.
  • A description pane that shows the name of the selected property and a short description of it.
Changing Property Settings
You can change property settings by using the Properties window while you design the user interface or by using program code to make changes while the program runs.



Project Window

A Visual Basic program consists of several files that are linked together to make the program run. The Visual  Basic 6.0 development environment includes a Project window to help you switch back and forth between these components as you work on a project.



 Project Window Components
The Project window lists all the files used in the programming process and provides access to them with two special buttons: View Code and View Object.

Displaying the Project Window
To display the Project window, click the Project Explorer button on the Visual Basic toolbar. If the window is currently docked, you can enlarge it by double-clicking the title bar. To re-dock the Project window, double-click its title bar again.

Adding and Removing Files
The project file maintains a list of all the supporting files in a Visual Basic programming project. You can recognize project files by their .vbp file name extension. You can add individual files to and remove them from a project by using commands on the Project menu. The changes that you make will be reflected in the Project window.

Note: In Visual Basic versions 1 through 3, project files had the .mak file name extension. In Visual Basic versions 4, 5, and 6.0, project files have the .vbp file name extension.

Adding Projects
If you load additional projects into Visual Basic with the File menu Add Project command, outlining symbols appear in the Project window to help you organize and switch between projects.



Code Window

You can create much of your program by using controls and setting properties. However, most Visual Basic programs require additional program code that acts as the brains behind the user interface that you create. This computing logic is created using program statements — keywords, identifiers, and arguments — that clearly spell out what the program should do each step of the way.
You enter program statements in the Code window, a special text editing window designed specifically for Visual Basic program code. You can display the Code window in either of two ways:

  • By clicking View Code in the Project window.
  • By clicking the View menu Code command


Form Layout Window

The Form Layout window is a visual design tool. With it, you can control the placement of the forms in the Windows environment when they are executed. When you have more than one form in your program, the Form Layout window is especially useful — you can arrange the forms onscreen exactly the way you want.

To position a form in the Form Layout window, simply drag the miniature form to the desired location in the window.