|
|
Sign In Link to us |
|
Home 1. Introduction 2. Introducing VB 2.1 VB Concepts 2.2 Object Orientated 2.3 VB Windows 3. Projects 4. Containers 5. Controls 6. Code 7. Forms 8. Debugging Code 9. Error Handling 10. Objects 11. User Controls 12. Data Projects 13. API 14. Distribution
|
2. Introducing VB2.1 VB Concepts2.1.1 EnvironmentVisual Basic is shipped as part of the Visual Studio suite. This package also contains applications such as Visual C++, Visual SourceSafe, Visual InterDev, Visual J++ and common components, such as Bookshelf Basics (Help). Up to version 4, Visual Basic was designed for use with both 16 and 32 bit Windows operating systems (Windows 3.11/95/NT). In version 6, Visual Basic was designed to run only under a 32 bit Windows operating system (Windows 95/98/ME/2000/NT). Commonly used components and commands are contained within the Visual Basic Runtime Libraries. These libraries are installed as part of Visual Basic and shipped with your application when you use the 'Packaging & Deployment' wizard to create a Setup program. They are usually called "Vbrun???.dll" and installed into the Windows/System directory. As you use third-party or custom libraries, these too will require installation by your Setup program. This is necessary so that anybody who installs your application onto a PC that hasn't got Visual Basic installed can still run it. A cut-down version of Visual Basic is shipped with Office. This version (Visual Basic for Applications or "VBA") can be used to develop methods and functions inside Office applications. Due to licensing constraints and file size considerations, some of the functionality in Visual Basic is not present in VBA.
2.1.2 Execution This meant that in large complex programs, keyboard and mouse inputs could be missed when the program was 'busy' - say doing some calculations inside a subroutine where the keyboard scanning is not done. Visual Basic does not operate sequentially like this. Visual Basic is driven by Events - pieces of code are executed in response to something happening. When you click on an application window, a Click event has occurred. The Click event has an associated subroutine which you may put code into to determine what happens if the Application window is clicked. The application is then static; doing nothing (actually, Windows automates system events during these periods, such as re-drawing forms that have been re-sized). This concept means that a program is a collection of associated subroutines. These subroutines can be invoked as a result of an Event such as a mouse click, or can be programmatically invoked by the code. Each object that is used in Visual Basic (such as a Form or Control) has a different set of Events that are applicable. Thus, in addition to an object having properties, such as width, height and color, an object also has Events and methods (subroutines) associated with these Events. 2.2 Object Orientated Methodology2.2.1 ObjectsAn Object in Visual Basic is an elemental part of the application that has constituent characteristics that can be accessed by the application. These characteristics have special names, which will be made clear later, but for now we'll call them characteristics. An Object's characteristics are accessed using the dot (".") modifier. For each dot in the term, you are asking Visual Basic to drill down another level. An Object's characteristic could itself be an instance of another Object.
Example:
ObjCar.CarBodyColour
Engine
Tyres
But, the characteristic "Engine" is itself an object, with the following characteristics:
Engine.IsDiesel
Make
Valves
BHP
Plugs
And again, the characteristic "Plugs" is an Object with the following characteristics:
Plugs.Count
GapSetting
Size
From the above information, we could refer to any characteristic of "objCar" within the whole range of subcategories, using the dot modifier as follows:
Access the colour of the bodywork: objCar.CarBodyColour Check if this car is a diesel or not: objCar.Engine.IsDiesel Check the gap setting for the spark plug: objCar.Engine.Plugs.GapSetting This philosophy could be employed for just about any subject matter you need. It forms the basis on which Visual Basic (and other languages) is designed to operate. The structure of the Object and it's characteristics is known as an Object Model.
Exercise i: Think of a different category and design your own Object Model for it on a piece of blank paper.
2.2.2 Class versus Instance To continue with our car example, let's assume we are writing an application to store information about different type of car. We already have the Object Model, so we can just declare new Instances of it for the different cars:
Dim FordEscord As objCar Dim VauxhallAstra as objCar Dim FiatUno as objCar
Note:
Note the use of the keyword Dim. This declares to Visual Basic that you want to define (or 'dimension') a new variable.
The As modifier tells Visual Basic what Type you want the new variable to be. For example, if you declared a variable as follows,
Visual Basic would create a variable called "strA" as a "String" type.
Dim strA As StringEach of these new Instances of the Object is assigned the framework structure that has been declared for their Type (objCar). Once they have been declared, they operate like 'photocopies' of the original and like photocopies, you can write over each 'copy' with information unique to that copy. For example:
FordEscort.Engine.IsDiesel = "Yes" FiatUno.Engine.IsDiesel = "No" VauxhallAstra.Engine.IsDiesel = "No" The Class of an Object can be thought of as the mould for the instances of that object. 2.3 VB WindowsWhen Visual Basic is first installed, it is configured to display various windows that help the developer to move around and program more efficiently. It is possible, however, to close these windows so that they do not appear when Visual Basic is next launched.
![]() This is a summary of the various windows and tools available and how to access them.
2.3.1.3 Toggle Folders
2.3.2 Properties Window Each time an element is selected, it's Properties are displayed in the Properties Window. From here they can be read and/or changed. The Properties Window is usually on the right-hand side of the screen, however if it isn't open select "Properties Window" from the View menu or press F4.
Several toolbars are available within Visual Basic. Toolbars are shortcuts to regularly used menu options.
![]() Toolbars can be opened from the "Toolbars" sub-menu within the View menu. | |||||||||||