NetScape COMPUTER ACADEMY1
Chapter 1
INTRODUCTION
Introduction
In the Beginning VISUAL STUDIO was a loose collection of programming tools and utilities. VISUAL STUDIO 6.0 is now starting to show tighter integration between these tools and utilities. VISUALSTUDIO is a collection of Microsoft Visual Development applications and related tools. This collection is intended to provide a single framework for all the development needs of an enterprise development team. The tools are designed to complement each other while providing a complete design, development, and deployment environment.
VISUAL STUDIO contains following tools
- VISUAL BASIC
- VISUAL C++
- VISUAL J++
- VISUAL INTERDEV
- VISUAL FoxPro
The tools in VISUAL STUDIO are designed to address the varying development needs of different types of developers, including Web developers, Application developers, Enterprise developers, and content developers.
A Web Developer is one who is developing and deploying applications over the Web. Such a person might use Microsoft Internet Information Server (IIS) and Microsoft SQL Server along with Active Server Pages (ASP) on the back end, and Web pages containing VBScript, ActiveXControls, and Java Applets on the front end.
An Application Developer is one who is developing and deploying standalone Windows applications and tools. They might use a combination of VISUAL BASIC and VISUAL C++ to develop such programs, using Microsoft Access or any other RDBMS as their database.
An Enterprise Developer is one who is developing strategic business applications that help manage a company’s enterprise resources. Enterprise developers are interested in using teams of developers to build business components that are scalable and can be distributed around the enterprise.
VISUAL BASIC was introduced to the public in 1991. It has improved with every release. With each release, the product has gotten both better and more popular. By 1998, VISUAL BASIC was the primary language used by more than half the developers in United States. This book is designed to be a completed desk reference to the many techniques and tools related to VISUAL BASIC.
VISUAL BASIC is an ideal programming language for developing professional applications for Microsoft Windows. It makes use of Graphical User Interface (GUI) for creating powerful application.
When programming in visual Basic Developer must decide how the application interacts with the user. The user may do any event in the application on various controls.
Windows introduced the concept of a message. Every action you perform in Windows generated one or more message. For instance, if the user moves the mouse across the screen, a series of messages are generated for each position the mouse occupies while it is being moved. If the user moves the mouse over the window for an application that is running, windows send these messages to that application. The application then has to determine if the user is doing something within itself, or if the user is just “passing through.” Every application has to look as every message sent by Windows and make this determination. The code required to make this work is lengthy and complex, to say the least. Besides having to handle simple messages such as a mouse movement, a Windows application also has to handle complex actions, such as when the user moves a window from one place to another. Windows tells your program what the user is doing, but it doesn’t do any of the work of handling the user’s action for you. Your application has to repaint your windows in a new position, for instance. Even after you have dealt with all the windows messages you might receive, you’re still not done. Your program still has to have code to handle all of your applications features.
VISUAL BASIC revolutionized all this tedious code. Instead of a programmer’s having to write lengthy code to make a window respond to the mouse, VISUAL BASIC handles all those actions and hides them from the programmer. To indicate to your program that the user clicked the mouse, VISUAL BASIC provides an event instead of a series of messages. You then write code to respond to the event and not the message. With the introduction of event, VISUAL BASIC programmers could concentrate on writing application’s features and not worry about the low-level things such as why a button click worked. They could simply write the code to run when a button was clicked. The code that runs when the user clicks a button or any other event is known as an event handler.
VISUAL BASIC also provides a design environment in which the programmer could draw an applications window instead of writing code to create them. This ability to rapidly draw the interfaces of an application made VISUAL BASIC into an excellent tool for creating prototypes. A prototype is a preliminary version of an application used for discussion among designers. For consultants, a prototype is an excellent way to show your client what the application might look like.
Coding in VISUAL BASIC is quite transition to traditional. Work of the user is guided through a linear path of execution and is limited operations. In a GUI environment, the number of options open to the user is much greater, allowing more freedom to the user and developer. Features such as user friendliness, faster application development, ActiveX technology and Internet features make VISUAL BASIC an interesting tool.
VISUAL BASIC was developed from BASIC (Beginners All-Purpose Symbolic Instruction Code) programming language.
VISUAL BASIC 6.0 requires at least Windows NT/Windows 95/98, 486 Processor and a minimum of 16 MB RAM. A complete installation of VISUAL BASIC 6.0 (Enterprise Edition) requires more than 250 MB hard disk space.
Chapter 2
Getting Started
Event Driven Programming
Forms and controls are the basic elements in the user interface of any VISUAL BASIC application. In VISUAL BASIC these elements are called as objects. Each object has their own properties and react to external events.
Starting Visual Basic
VISUAL BASIC is a component of Visual Studio.
Click Start Microsoft Visual Studio 6.0 Microsoft Visual Basic 6.0 or Double click on the Vb6 icon if it is available.
A New Project dialog box will appear with following options.
New This tab enables us to create a New project. In this window, you’ll see some of the project types that VISUAL BASIC supports. They are
- Standard Windows EXE Programs
- ActiveX Exe files
- ActiveX DLLs
- ActiveX Controls
- Programs written by VISUAL BASIC Application Wizard
- Data Projects
- IIS(the Microsoft Internet Information Server) applications
- VISUAL BASIC add-ins
- ActiveX document DLLs
- ActiveX document EXE files
- DHTML applications
- VISUAL BASIC Enterprise Edition Controls
Existing This tab enables us to select already existing project
Recent This tab lists the Visual Basic projects that are used recently.
Whenever a project is opened or a new project is started, Visual Basic 6.0Integrated development Environment (IDE) appears.
Selecting standard Exe in the project dialog box creates a new project. This will open a new project named project1.
Creating a Project in VISUAL BASIC
There are three different editions of VISUAL BASIC:
- The Learning Edition:- The most basic edition. This edition allows you to write many different types of programs, but lacks a number of tools that the other editions have
- The Professional Edition:- Designed for professionals. This edition contains all that the Learning Edition contains and more, such as the capability to write ActiveX controls and documents.
- The Enterprise Edition:-Which is the most complete VISUAL BASIC edition. This edition is targeted towards professional programmers who may work in a team and includes additional tools such as Visual SourceSafe, a version-control system that coordinates team programming
IDE- Integrated Development environment.
IDE is a commonly used term in the programming world to describe the interface and environment that we use to create our application. It is also referred as design environment. The IDE is made up of following components.
Menu Bar, Tool Bar, Toolbox, Project Explorer, Properties Window, Form Layout Window, Form Designer, Object Browser.
In VISUAL BASIC IDE is Multiple Document Interface (MDI) format. In this format, the windows associated with the project stay within a many container form.
Menu bar :- The menu bar displays the commands that are required to build an application.
Tool bar :-The tool bar provides quick access to the commonly used commands and a button in the toolbar is click to carry out the action represented by it. Visual Basic has four default tool bars that can be made to appear on the screen or hidden using .
View Tool bars in menu section.
1. Standard It contain all preliminary icons
2. EditEditing VISUAL BASIC code.
3. Debug To assist in finding errors in the coding.
4. Form EditorsTo adjusting items on the form.
Chapter 3
Toolbox, Form, Properties & Project Explorer
The Toolbox
Tool box contain number of controls that can placed on a form when a mouse cursor is placed on the control a pop up tool tip will appear displaying a short description of the control. You use the toolbox to add controls to your projects, and you document so in a very easy way-just click a tool, and draw the new button in the form. The toolbox is loaded with controls you can add to your forms-textboxes, labels, list boxes, image controls, checkbox controls etc. When you add a new ActiveX control to your project, that control appears in the toolbox, and you’re ready to add it to your form.
Tool Box Controls
Pointer:- Pointer is not really a component. It provides a way to move and resizes other controls.
Label:- Labels lets you provide information to the user about the purpose of your form controls. Labels display a text that the user cannot modify or interact with. You can use this control to display text that labels other parts of the form that don’t have their own captions. You can change the text in a label control at runtime or design time by setting Caption property. You can also format, word-wrap, or size a label to fit its text. You can size the label as desired using Top, Left, Width and Height properties. To format text in a label use its properties like Autosize, WordWrap, FontBold, FontItalic, FontName, FontStrikethru,FontUnderline etc. To align the text in label use the Alignment property, which have the values 0-VbLeftJustify, 1-VbRightJustify, and 2-VbCenter. You can use label controls to give access keys to other controls like Textbox. For this type the Caption of a Label with an ampersand [&] in front of the character for which you want to use as access key, draw the control for which you want to set the focus. That is the control should have the next TabIndex property value. Labels do not accept focus, so when you press the access key, it will set the focus to the next control in TabIndex order. When you access keys, make sure to set the label’s UseMnemonic property to True.
Framecontrol: - The Frame control can be used to divide the controls into logical groups. They serve as a visual and functional container for other controls. For example you can draw different option button groups in different frames. You can change the Appearance of a Frame using Appearance property. To set the size of a Frame use Top, Left, Width, and Height properties. To group controls, first draw the Frame control and draw the controls in it. If you draw a control outside the frame and then try to move it inside, the control will be on top of the frame, not in it, which means the control will not be grouped with other controls in the frame.
CheckBox:- The Checkbox control is used to provide the user a Yes or No choice for a particular question. It has three values 0 (Unchecked), 1 (Checked) and 2 (Grayed). You can use a checkbox’s Value property to determine its state. The most commonly used event for Check box is Click event. You can set the caption of a checkbox control using Caption property.
Textbox:- Text box is a control used to display the messages and enter text. Textbox can be used in a variety of configurations, including a multiline version that can hold unlimited amount of text. It can also add its own scrollbars if the amount of text is larger than the visible size. Text in a Textbox can be edited. You can also lock the textbox to disable editing. To create Multiline textbox, set its Multiline property to True. You can set scrollbars to a textbox and its values are 0-None, 1-Horizontal, 2-Vertical, and 3-Both. To change the alignment of a Textbox, set Alignment property as 0-Left, 1-Right, and 2-Center. To Make a Textbox Readonly, you can set Locked property to True. To Disable a Textbox, set its Enabled property to False. You can also format the Font, Fontsize etc. using Fontname, FontBold, FontItalic, FontSize etc. The SelLength property returns or sets the number of characters selected, SelStart property returns or sets the starting point of selected text, and SelText property returns or sets the string containing the currently selected text. To convert a standard TextBox into Password box, you just assign some character usually[*] to the textbox’s PasswordChar property.
ListBox:- The list box displays the list of items from which user can select. You can add items to the list box using AddItem method and also remove an item using RemoveItem method. To clear all the contents of listbox use Clear method. There are variety of properties to count the no. of items, sorting the list etc. To count the total no. of items in a listbox use ListCount property, to Sort the Listed items set Sorted property True. The ListIndex property returns the Index value of currently selected item in the Listbox. If none is selected ListIndex returns –1. You can use Listbox’s Click, DblClick events to handle different operations. To Create Checkmarks in a Listbox set Listbox’s Style property to 1-Checkmark List Box.
ComboBox:-The ComboBox is a very flexible control. It combines a drop-down List Box and a TextBox in one control. This allows the user to select an item from the drop down list box. You can create three different styles of ComboBox.
i)Dropdown List: - This style of ComboBox allows the user to pick from a list but not type into the text portion of the control.
ii)SimpleCombo:- In this Style, the user can type a choice, but the list drop down under text box. This style is rarely used.
iii)DropdownCombo: - This style provides both features: a drop-down list as well as a text portion where the users can type their choices.
Use the AddItem method to Add items, RemoveItem method to Remove Items from a Combo Box. You can use the events like Click, DblClick, Change etc to perform different operations. The Sorted property is used to create sorted list. Use the Clear method to Clear the contents of Combo Box. You can also Lock the Combo Box using Locked property. List Count property returns the Number of Items in Combo Box, ListIndex returns the Index of currently selected item.
ScrollBar:- Horizontal Scroll bar, Vertical Scroll bar allows the user to select a value in the specified range. This type of control is intuitive for the user because, as the user drags the control, another change on the form such as color or text also changes. To add horizontal or vertical scrollbar, just pick the control and draw it on your form. After you place the scrollbar, you can change its Maximum and Minimum values using Max and Min properties. The Maximum value must be between 0 and 32767. There are three ways to change the setting of a scrollbar, by moving the thumb, by clicking the an arrow, and by clicking on the area between the thumb and arrow button. You can set the LargeChange property to determine how much the scroll bar value should change when user clicks on the scrollbar itself, not the thumb or arrow. Set Smallchange property to determine the amount of value to be changed when the user clicks on arrow button. To get a scrollbar’s current value use Value property. When the user changes the setting in a scrollbar, a change event occurs and you can react to those changes with an event handler attached to that event. The change event occurs after the action is completed. The Scroll event updates as the action is happening. It’s very useful to be able to update the screen as the user scrolls. To show or hide scrollbars use Visible property.
Timer :- Timer control allows you to react to elapsed or passing time while an application is running. The timer can be programmed to notify you after a number of milliseconds have elapsed. A millisecond is 1/1000th of a second. The maximum interval is just slightly larger than a minute. Timer control executes the timer events at specified intervals. This control is not visible at run time. To enable or disable this control use Enabled property. The Interval property sets the interval between Timer events. This control only has the event handler Timer where you can write the code when the Timer event occurs.