Wednesday 13 November 2019

What is Visual Basic ?




Visual Basic is a tool that allows you to develop Windows (Graphic User

Interface - GUI) applications. The applications have a familiar appearance to the
user.
Visual Basic is event-driven, meaning code remains idle until called upon to
respond to some event (button pressing, menu selection, ...). Visual Basic is
governed by an event processor. Nothing happens until an event is detected.
Once an event is detected, the code corresponding to that event (event
procedure) is executed. Program control is then returned to the event processor.





Some Features of Visual Basic -:





Full set of objects - you 'draw' the application

Lots of icons and pictures for your use
Response to mouse and keyboard actions
Clipboard and printer access
Full array of mathematical, string handling, and graphics functions
Can handle fixed and dynamic variable and control arrays
Sequential and random access file support
Useful debugger and error-handling facilities
Powerful database access tools
ActiveX support
Package & Deployment Wizard makes distributing your applications simple.





Visual Basic 6.0 versus Other Versions of Visual Basic -:




The original Visual Basic for DOS and Visual Basic For Windows were

introduced in 1991.
Visual Basic 3.0 (a vast improvement over previous versions) was released in
1993.
Visual Basic 4.0 released in late 1995 (added 32 bit application support).

Visual Basic 5.0 released in late 1996. New environment, supported creation of

ActiveX controls, deleted 16 bit application support.



features of Visual Basic 6.0 -:




Faster compiler

New ActiveX data control object
Allows database integration with wide variety of applications
New data report designer
New Package & Deployment Wizard
Additional internet capabilites



16 Bits versus 32 Bits -:










Applications built using the Visual Basic 3.0 and the 16 bit version of

Visual Basic 4.0 will run under Windows 3.1, Windows for Workgroups,
Windows NT, or Windows 95

Applications built using the 32 bit version of Visual Basic 4.0, Visual Basic

5.0 and Visual Basic 6.0 will only run with Windows 95 or Windows NT
(Version 3.5.1 or higher).

In this class, we will use Visual Basic 6.0 under Windows 95, recognizing

such applications will not operate in 16 bit environments.





Structure of a Visual Basic Application -:



Application (Project) is made up of -:



Forms - Windows that you create for user interface.


Controls - Graphical features drawn on forms to allow user interaction

(text boxes, labels, scroll bars, command buttons, etc.) (Forms and
Controls are objects.)


Properties - Every characteristic of a form or control is specified by a

property. Example properties include names, captions, size, color,
position, and contents. Visual Basic applies default properties. You can
change properties at design time or run time.


Methods - Built-in procedure that can be invoked to impart some action to

a particular object.


Event Procedures - Code related to some object. This is the code that is

executed when a certain event occurs.


General Procedures - Code not related to objects. This code must be

invoked by the application.


Modules - Collection of general procedures, variable declarations, and

constant definitions used by application.



Steps in Developing Application -:




There are three primary steps involved in building a Visual Basic application -:


1. Draw the user interface

2. Assign properties to controls
3. Attach code to controls




Drawing the User Interface and Setting Properties -:


Visual Basic operates in three modes -:




Design mode - used to build application


Run mode - used to run the application


Break mode - application halted and debugger is available.


We focus here on the design mode .





Six windows appear when you start Visual Basic -:




The Main Window - consists of the title bar, menu bar, and        toolbar. The

title bar indicates the project name, the current Visual Basic operating
mode, and the current form. The menu bar has drop-down menus from
which you control the operation of the Visual Basic environment. The
toolbar has buttons that provide shortcuts to some of the menu options.
The main window also shows the location of the current form relative to
the upper left corner of the screen (measured in twips) and the width
and length of the current form.











The Form Window  is central to developing Visual Basic applications.  It is where you draw your application.  








The Toolbox is the selection menu for controls used in your application.








The Properties Window is used to establish initial property values for objects.  The drop-down box at the top of the window lists all objects in the current form.  Two views are available:  Alphabetic and Categorized.  Under this box are the available properties for the currently selected object. 






 The Form Layout Window shows where (upon program execution) your form will be displayed relative to your monitor’s screen.





 The Project Window displays a list of all forms and modules making up your application.  You can also obtain a view of the Form or Code windows (window containing the actual Basic coding) from the Project window. 





 As mentioned, the user interface is ‘drawn’ in the form window.  There are two ways to place controls on a form -: 


1. Double-click the tool in the toolbox and it is created with a default size on the form.  You can then move it or resize it.  

 2. Click the tool in the toolbox, then move the mouse pointer to the form window.  The cursor changes to a crosshair.  Place the crosshair at the upper left corner of where you want the control to be, press the left mouse button and hold it down while dragging the cursor toward the lower right corner.  When you release the mouse button, the control is drawn.
 3.To move a control you have drawn, click the object in the form window and drag it to the new location.  Release the mouse button. 

4.To resize a control, click the object so that it is select and sizing handles appear.  Use these handles to resize the object.   







A toolbar is becoming a standard feature of Windows applications. Toolbars provide functionality to a user through an easily accessible, graphical interface. For common functions the user does not need to navigate through a menu or remember shortcut keys to use an application.







The menu bar is the standard feature of most Windows applications. The main purpose of the menus is for easy navigation and control of an application. Some of the most common menu items are File, Edit, View, Tools, Help and more.







A file is a collection of bytes stored on the disk with a given name (called as filename). Every development tool provides access to these files on the disk. ... Binary For reading and writing arbitrarily structured files. Opening the file using Open statement. A file is opened using OPEN statement in Visual Basic.





Project Explorer Window. The Project Explorer allows you to add items to the project and manage their related build action and additional properties. ... The root project node is always named after the project and lets you add folder and file items to the root folder of the project.









Properties Window. This window allows us to change some of the properties associated with an object at design time. ... When you select multiple controls, the Properties window contains a list of the properties common to all the selected controls.








Code Window in VB. The Code window is found to the right of the Project Explorer. It displays the VBA code for the object currently highlighted in the Project Explorer. If the Code window is not visible when you open the Microsoft Visual Basic window, you can make it visible by selecting Code under the View menu.







You can use the immediate window in VB to get the current values of variables and to run other code. To show it click View | Immediate. You can only use the immediate window when code execution is paused. Entering a ? and then the variable name or property will return its value, press RETURN to execute the query.








The Watch Window. The Watch Window allows you to watch certain expressions, in certain modules and/or procedures, and then stop code execution when it changes. To show the Watch Window, select Watch Window from the View menu. Adding a Watch. To add a watch, select Add Watch from the Debug Menu.







A ToolBox is a palette that contains lots of controls for designing and creating the Visual Basic projects. There are different category of the Tools available in the ToolBox. Every controls that we use in our windows form or web form will reside in the ToolBox.









oops ---
Although VB6 may have some OOP capabilities, it is not an object-oriented programming language. Visual Basic 6 is not an object-oriented programming language because it does not have inheritance capabilities. On the other hand, VB2008 is an Object Oriented Programming Language, just like other OOP such as C++ and Java.






Objects and classes. Each object in Visual Basic is defined by a class. A class describes the variables, properties, procedures, and events of an object. Objects are instances of classes; you can create as many objects you need once you have defined a class





A property is a value or characteristic held by a Visual Basic object, such as Caption or Fore Color. Properties can be set at design time by using the Properties window or at run time by using statements in the program code. Object.




Methods Functions and Sub Procedures. Methods help us to handle code in a simple and organized fashion. Functions return a value, but Sub Procedures does not return any value. Methods are basically a series of statements that are executed when called.




An event is a signal that informs an application that something important has occurred. For example, when a user clicks a control on a form, the form can raise a Click event and call a procedure that handles the event. Events also allow separate tasks to communicate.