Chapter 1:- Fundamentals of Visual Basic
A basic is the fastest and easiest way to create applications for Microsoft Windows. Visual Basic provides complete set of tools to simplify rapid application development both for the experienced professional and new window programmers.
In the name Visual basic- the "Visual" part refers to the method used to create the graphical user interface (GUI). Unlike many languages which requires numerous lines of coding to describe the appearance and location of interface elements, Visual Basic provides pre-built provides per-built objects that can be used to from the Graphical User interface (GUI).
The "Basic" Part refers to the BASIC language as its basic syntax of statements is retained by Visual Basic. But visual basic not contains several hundred statements, functions, and keywords, many of which relate directly to the windows GUI.
The Visual Basic programming language is not unique to Visual Basic. The Visual Basic programming system, applications edition included in Microsoft excel. Microsoft access and many other window applications uses the same language. The Visual Basic scripting Edition (VBScript) is a widely used scripting language and a subject of the Visual Basic language. So mastering Visual Basic also helps to master these other areas.
New features of Visual Basic 6.0
Whenever a product's version number increases by one, it means that several enhancements have been made over the previous version. Before looking at the completely new additions to Visual Basic 6.0, this section presents general Visual Basic features briefly.
The compiler is Visual Basic gives many different options for optimizing the compiled code, such as Optimization for fat code, optimization for small code and favor of Pentium pro etc.
The Visual Basic is a very open environment that supports the Client/Server architecture, ActiveX, Component Object Model (COM), Distributed Component Object Model (DCOM). It also supports Open Database Connectivity (ODBC).
Intelli Sense
A new feature that Microsoft calls intelliSense enables the system to react in real time during coding. There are five basic intelliSense features:
Complete word
List members
List constants
Quick info is a feature that presents the syntax of the procedure, which is being typed, in a tool tip like window. It even goes one step further in that it will bold the specific parameter which is being coded in real time.
Complete word is a feature that automatically completes the word which is typed in real time, after enough characters that make the word distinct within the list of available words, has been typed.
Data tips is a very useful feature that simply shows the value of the variable in a yellow too tip format at run time.
List members is a feature that is used to simply list all of the properties or methods available constant values for a given property are listed.
Multiple projects can be loaded into the IDE – integrated Development Environment (Explained shortly) and treated as one. For example, a standard project and an active X project can be loaded at the same time. This saves tremendous amount of time for coding and debugging. Here's a list of some other enhancements:
v Break points will be toggled simply with a mouse click,
v Bookmarks can placed for quick location.
v Properties in the property window can be manipulated alphabetically or even by category.
v A nice new feature is block comment and uncomment. With the click of a mouse button, all highlighted code will be commented or uncommented
v Aligning and formatting can easily be applied to one or more controls.
Visual Basic 6.0 features
This section briefs what are newly added in Visual basic 6.0 in various categories.
ADO (ActiveX Data Objects)
It allows to use drag and drop to quickly create reports from any recordset, including hierarchical recordset.
Hierarchical Flex Grid control
It is an updated version of the Flex grid control that, in additing to supporting all the functionality of the Flex grid control, can display a hierarchy of ADO recordset. Each recordset returned is displayed as a separate band within the grid and can be formatted independently.
Data List Control, Data Combo Controls
These controls are OLE DB version of the DBList and DB combo controls. They also support the new ADO Data control.
New in Internet Features
IIS Applications
This feature enables to write server side internet applications that use Visual Basic code to respond to user requests from a browser.
DHTML Applications
DHTML Application allows to write Visual Basic code to respond to actions on an HTML page, without transferring processing to the sever.
Getting in to Visual Basic
To start Visual Basic
v Click the start button in windows Taskbar, choose Microsoft Visual Basic 6.0 group and click the Microsoft Visual Basic 6.0 item.
Simply double click the Microsoft Visual Basic 6.0 icon on the Desktop.
Standard EXE it is a typical project type and used to create standard executable files.
ActiveX EXE, ActiveX DLL these types of projects are used to create ActiveX code. Components which are OLE automation serves. These two types of projects are identical I functionality, but are packaged differently (as executable files or Dynamic Link libraries)
ActiveX Control This type of projects used to create new ActiveX controls.
Visual Basic Application wizard It generates a new, fully functional application from which more complex application can be built.
Data project It creates a project that automatically includes data report and data environment…
Active X Document EXE, Active X document DLL These project types are used to active X document. Which are in essence Visual Basic applications that can run in the web browser such as Internet Explorer.
IIS Application, DHTML application. These projects are used to create internet applications for both server-side and client side.
The new project dialog box as figure has three tabs;
v New Existing Recent
The new tab allows to select the types of a new project, as explained already. Switching to the existing tab will enable to select an existing project and open it. Switching to the existing tab will enable to select an existing project and open it. Switching to the recent will enable to select and open the most recently worked projects during the last few days.
Select the standard EXE icon in the New project window, and click the OK button. This will open the integrated Development Environment (IDE) as in figure.
Figure: Integrated Development Environment
The following sections briefly explain the parts of the IDE.
The menu bar
The menu bar contains the commands needed to work with the Visual Basic. The Basic menus are:
v File: Contains the commands for opening and saving projects and creating executable files and list of recent projects.
v Edit: Contains editing commands (Undo, copy, paste, and so on) plus a number of commands for formatting and editing code (find replace)
v View: Contains commands for showings or hiding components of the IDE.
v Project: Contains commands that add components to the current project reference to windows objects, and new tools to the Toolbox.
v Format: Contains commands for aligning the control on the form.
v Debug: Contain usual debugging commands.
v Run: Contain the commands that start, break, and end execution of the current application.
v Tools: Contains tools needed in building active X components and ActiveX controls;
v Contains the command to start the menu editor and the options command, which lets to customize the environment.
v Add-Ins: Contains add- ins that can be added and removed as needed. By default, only the Visual data manager Add in is installed in this menu. Add n manager command
v Window: Contains the commands to arrange windows on the screen; the standard window menu of a windows application.
v Help: Contains information to help user as her works.
The tool bars
Provided quick access to commonly used commands in the programming environment. By default, the standard toolbar is displayed when Visual Basic starts. Additional toolbars for editing, form design, and debugging can be toggled on or off from the tool bars command on the view menu. For example, to view the debug toolbar, choose view toolbar and check the debug option. Like wise to hide the debug follow the same procedure, but this time uncheck the debug option.
Toolbar can be docked beneath the menu bar or can 'float' if the vertical bar on the left edge is selected and dragged away from the menu bar. Each toolbar and its brief description are given below.
à Standard toolbar is just below the menu bar and is displayed by default.
The Edit toolbar contains the commands of the Edit menu.
The Debug toolbar contains the commands of the Debug menu.
The Form Editor menu contains the commands of the Format menu.
The Project Explorer
Lists the forms and modules incurrent project. A project is the collation of files that used to build an application.
The project components are organized in folders, and the project window is called the application's user interface. By default, the toolbox contains the pointer icon and the icons of 20 intrinsis controls.
To place a control, say command button, on the form
à Select the command button with the mouse.
à Move the mouse over the form. When the mouse pointer is over the form it will turn to cross.
à Draw the control on the form, just as drawing a rectangle.
The properties window contains the property setting for the selected control. Properties are attributes of an object, such as its size, font, background color and so on. By setting these properties the appearance of the selected control can be adjusted easily. For example to change the caption and appearance of a command button follow the steps given below.
Select the command button icon on the tool bar and draw the button on the form. The button will appear with its default name as its caption, as in
Make sure that the command button is selected and press F4 or click the properties window to make it as active.
In the properties window (Figure 2.4) locate the caption property and changes its value as Click & me
Placing ampersand before the letter M will make the caption of the command button to appear as click me. It meaning is that this button can pressed by using keyboard characters Alt and M (Alt + M).
To change the background color of the command button, locate the back color property and click the down arrow button next to the current value of the color. This will display the color selection box as in figure 2.5
Select the Inactive Title Bar color. Now the command button will appear as in figure 2.6
Note: when the color selection box is displayed, its palette tab might be active by default. This tab will show the colors alone. To view each color's description switch to the system tab.
Figure: New appearance of the Command Button
The Form Designer
The form designer enables to add controls, graphics, and pictures to a form to define the interfaces in the desired look. Each form in an application has it own form designer. The form designer displays two windows for each form.
The form itself (the enables of the user interface)
A code window (the code behind the elements of the form)
Double clicking on a form will bring its code window front. Double clicking on a from name in the project explorer window will bring the form to the front. Or to switch between these window easily, the view code and view form at he top of the project explorer window (Figure 2.7) an be used.
The Form Layout
The form layout window helps to position the forms of an application using a small graphical representation of the screen. This window is very useful in the application that uses multiple forms, because each form's position can easily be specified with respect to the main form. For example, assume that an application contains three forms. The form layout windows will show the layouts of the all three forms. Mouse can be used to drag these layouts to the desired location as in figure.
When the application shown all the forms, they will appears in the screen as in figure.
Figure: Forms – appearing on the Desktop as positioned in he Form Layout window
The Immediate Window
The immediate window is a debugging aid. While an application is running it can be paused and the immediate window can be used to examine or change the values of the application's variable. It can be used to execute simple basic commands even when the application is not running. For example, type print 30+40 in the immediate window and hit enter. The result 70 will appear in the next line.
It contains shortcuts to frequently performed action. When right mouse button click, context menu pops up with list of shortcuts specific to part of the environment where the mouse is right click, for example context menu displays items name components…., Add tab…., dock able, and hide, when the mouse is right clicked on the toolbox (figure 2.10)
Figure: Context menu that appears when the right mouse Button is clicked on the Toolbox.
Basic Scripting In Visual Basic
Microsoft Visual Basic scripting edition, the newest member of the Visual Basic family of programming languages, bring active scripting to a wide variety of environments, including web client scripting in Microsoft internet explorer and web server scripting in Microsoft internet information server. No scripting language including VBscripts has disc accessing features and so it is accepted to be a safe language to deploy in the web.
Easy To Use And Learn
If you already known visual Basic or Visual Basic for applications, VBScript will be very familiar already known Visual Basic, once you learn VBScripts on your way to programming with the whole family of Visual Basic languages.
It is a free language and so it can be used anywhere. We can write our VBSCRIPT program in notepad and execute it using internet explorer. You can use the SCRIPT element to and VBScript code to an HTML page.
The <SCRIPT> Tag
Any scripting language can be enclosed within a script tag in a ordinary HTML file. The script tag can be placed anywhere in the HTML page and its is better to place it in the head tag. We should mention the language as an attribute. It is a container tag.
<script language = vbscript>