Tuesday, May 8, 2012

How to add and remove toolbars in Visual Basic IDE

Toolbars are collections of small iconic buttons that reside in a bar underneath the menu bar. These buttons offer access to the most commonly used functions that you have in the Visual Basic menu structure. Toolbars are useful because rather than have to negotiate menus and submenus to do what you want, you click a specific button in the toolbar to call a specific functionality in the Visual Basic IDE.

ToolTips

ToolTips are little windows that appear when you hold the mouse pointer over a control or toolbar button for a few seconds. Inside these windows is some text that tells you what the control or toolbar button is about.
Toolbars usually reside under the menu and can be grouped into a single bar. Also, you can drag a toolbar onto the IDE's Code and Form windows to have it "float" for more convenient access.

Add or remove a toolbar to or from the IDE
1. Right-click anywhere on the menu bar, or choose Toolbars from the View menu. The toolbar pop-up menu appears .
You select a predefined toolbar type by right-clicking the VB toolbar.
2. Select the type of standard toolbar that you want from the pop-up menu. If a check is to the left of a toolbar type, that toolbar is already visible.

Using the Debug Toolbar

You use the Debug toolbar to test your program and resolve errors that might occur. When you debug a program, you do things such as run the code a line at a time, examine the values of variables, and stop the code at certain critical points or under certain conditions. For an in-depth discussion of debugging, see Chapter 21, "Debugging Your Applications."

Using the Edit Toolbar

You use the Edit toolbar when you're working with code in a Code window. The features of the Edit toolbar are similar to those of the Edit menu. You can Cut and Paste text. You can manipulate the layout of your code and do text selection, searches, and replacement. Also, you can use automatic coding features such as Quick Info.

An interesting VB IDE feature that the Edit toolbar uses is the Complete Word feature (also trademarked by Microsoft as Intelli-sense). This feature automatically completes a keyword for you. For example, if you were to type Ms into a code window and then invoke the Complete Word feature, Visual Basic would complete the word as MsgBox, an intrinsic Visual Basic function that displays a Windows message box. The Complete Word feature is very useful for avoiding syntax errors due to misspelling. For more information about the specifics of debugging, see Chapter 21.
The Debug toolbar enables you to access the debugging functions of the Visual Basic IDE.
You can access the extended Edit menu and some Debug menu functions from the Edit toolbar.

Using the Form Editor Toolbar

You use the Form Editor toolbar to size, move, and align controls on a form. The Form Editor toolbar has the same set of features as the Format menu.
You align and size multiple controls on a form with the Form Editor toolbar.
Notice the small downward-facing arrowheads to the right of the Align, Center, and Make toolbar buttons. These arrowheads indicate that a drop-down menu will appear when you select that toolbar button.

Working with forms and controls requires that sometimes you have to work with the ZOrder property of a control. ZOrder determines which control has the "right" to supersede the position of another control. Sometimes you might want one control to appear over another--an OptionButton over a PictureBox, for instance. You can accomplish this by dragging the OptionButton over the PictureBox. Alternatively, in code, you can set the value of the OptionButton's ZOrder property to 0. Then, no matter where you place the control at design time, the OptionButton will always be on top. When you place one control over another on a form, you're affecting each control's ZOrder property. The Z order determines the "top most-ness" of a control. Controls with a ZOrder value of 0 are always on top; however, if two controls each have a ZOrder value of 0, they nullify each other.

Using the Standard Toolbar

The standard toolbar is the central toolbar in the Visual Basic IDE. The standard toolbar offers many features found in the File, Project, Debug, and Run menus.
The standard toolbar gives you fast access to often-used functionality and information.

Visual Basic IDE

The Form Layout Window

Using the Form Layout Window, you can choose where your program will essentially show up once it is completed. As you can see, it already contains a small version of a form, which can be moved around the screen.

Right-clicking the Form Layout Window will also give you the possibility to select some positions (In the ‘Startup Position’-sub menu). The Form Layout Window is not something we will be using often. (Well, I don’t use it often. It’s up to you to decide whether or not you leave it visible, or just hide it).



The Properties Window

The window right above the Form Layout Window is the Properties Window.

This is one of the windows you will probably use a lot. It shows the properties of the currently selected object. What is a property, you ask? The definition from MSDN is: “A property is a characteristic of an object, such as size, caption, or color”.

Let’s look at this a little more in-depth, shall we? Imagine for a second we’re a God. We created a world, threw in trees, bushes, and what not; added a few animals, and are now working on tossing in a few people. Every person has a few characteristics: Eye color, hair color, a name, a shoe-size, etc. With the Properties Window, you can quickly see all the various properties on objects, and set or change current properties.

The Properties Window is made up out of three elements (As seen in the picture):
# Object Box
# Sort Tabs
# Property List

The Object box provides a list of objects currently in use in the project, of which you can set properties.

The Sort Tabs provide a quick way of sorting the Property List. You can sort either by category, or alphabetically. This is really a matter of choice, or habit. Use whichever way you prefer.

The Property List provides a list of all the properties that can be set for the currently selected object. The left column provides the property name, the right column shows the currently assigned value.
Under the Property List, a short description of the currently selected property is displayed. (You can turn this off by right-clicking the Property Window, and unchecking the Description option).


The Project Explorer
Above the Properties Window, we’ll find our good friend the Project Explorer.

The Project Explorer shows the different files that make up your project. Notice that in the above screen shot, I added a few extra files, to show a more extensive window than the one you will currently see.


The Toolbox
On the left side of the screen, you will find the toolbox.

The toolbox holds various ActiveX controls that you can use in your projects. In addition to the standard ones you already see, you can also add other controls (that could be provided by Microsoft, third-parties, or controls that you made yourself).


The Form Designer

In the middle of the screen, you will find the Form Designer.

The Form Designer shows you the interface of your application. You can use the Form Designer to determine exactly what your project is going to look like, which controls will be available, which text will be displayed where, etc, etc.
This leaves us with two more things to discuss concerning the interface. The toolbar, and the menu, both of which have a lot in common with standard Windows applications, but offer a few new functions. Let’s tackle the toolbar first.

The Toolbar

The Toolbar provides a number of icons, some of which you will undoubtedly recognize from programs as Word, or any other Windows Application. We’ll briefly describe the various icons here, but won’t go deeper into what they do for now, as we will get working with that gradually, as we advance more and more into the actual programming process. You can get little description-labels by hovering the cursor over the icon for a second.
The first three icons are specific to Visual Basic. The left-most one allows you to add other projects to the project you’re working on, the middle icon adds files to your project, and the right-most one allows you to create user-menus.

The next few ought to look rather familiar to anyone who worked with Windows before. The first icon is for Opening a file, the second one for saving a file. The third icon is for cutting, the fourth one for copying, the fifth one for pasting, and the sixth one is for searching. The two arrows on the far right are respectively for undoing and redoing operations.

Three VB-specific icons again. They might look familiar however. They highly resemble buttons as they are used on Stereo / Video equipment. They provide the same functionality as well. The first one runs a project, the second one pauses it, and the third one aborts (or stops) the project.

These icons are all short-cuts to the various windows we discussed earlier. The first one is the Project Explorer, the second one the Properties Window, the third one represents the Form Layout Window.
The fourth one is a new one. It points to the Object Browser which we will discuss in future articles.
The fifth icon is for the Toolbox, and the sixth is a new one again. It points to the Data View Window, which we will discuss when we get to the article about Connectivity to Databases. .
The right-most icon the Visual Component Manager; basically a repository database for storing reusable bits and pieces of code, files, components, etc in.

The last part of the toolbar is for keeping track of the position and size of controls. The leftmost part is for the position, while the right part lists the size of a control. To see what both do, double-click on one of the icons on the toolbar, which will make a control be added to your form. Rezise and move the control on the form, and the numbers will change.

The Menu

The Menu contains a few default Windows menu-items (like file, edit, view, help, etc.), and a few functions specific to programming (like Debug, Run, Project, etc.).
# File-menu; provides file-related functions. (Open / Save / New / Print)
# Edit-menu; provides edit-related functions (Cut / Paste) as well as some look-up functions.
# View-menu; provides functions to access various Windows.
# Project-menu; provides ways to add files, and edit properties of the current project.
# Format-menu; provides functions to format controls on the form.
# Debug-menu; provides functionality to test your code, as well as tracking down errors.
# Run-menu; provides different ways to start and end a program.
# Query-menu; provides database-functionality. Only available in Enterprise Edition.
# Diagram-menu; provides database-functionality. Only available in Enterprise Edition.
# Tools-menu; offers some nifty tools, like wizards.
# Add-ins-menu; offers ways to integrate various external programs into VB.
# Window-menu; provides functionality to rearrange various Windows in the environment.
# Help-menu; provides… *drum roll* help.
That concludes the description of the environment
ethods.

Monday, May 7, 2012

Introduction to Visual Basics


The first thing you need to do is open a Visual Basic program. From the Windows Start menu, choose Programs, Microsoft Visual Studio 6.0, and then Microsoft Visual Basic 6.0.
When you start VB, you're taken to the Visual Basic Integrated Development Environment (IDE). This is your programming workbench, the place where you create your programs. Notice that the IDE presents what looks like an empty window containing some dots and a title bar with the word Form1. This window is a form, the primary building block of a Visual Basic application. An application can have many forms or one form.

Visual Basic Environment:

VB IDE

IDE is an acronym for Integrated Development Environment. The IDE is the workbench on which you make your programs in Visual Basic.

The Visual Basic IDE is a collection of menus, toolbars, and windows that make up your programming workbench . Each part of the IDE has features that affect different aspects of your programming activity. The menu bar lets you direct the overall activity and management of your programming. The toolbar enables you to access much of the menu bar's functionality through various toolbar buttons. Forms--the basic building blocks of Visual Basic programs--are presented in a Form window. You use the ToolBox to add controls to the forms of your project. The Project Explorer displays the projects on which you're working, as well as the different parts of each of those projects. You browse and set a control, form, and module's properties within the Properties window. Finally, you position and view a form or forms onscreen within the Form Layout window
The VB IDE is the programmer's workbench. Let’s run Visual Basic for the very first time.

For now, select Standard EXE, and click on Open. The next Visual Basic will add a few things for you, to accomplish the standard setup it needs for creating a Standard Executable (Which eventually will be a runnable program with a .exe extension).

The Visual Basic Interface

The screen you see now will look more or less similar to this one.



Why Visual Basic

• Visual Basic was designed to be easy to learn and use.


• The language not only allows programmers to create simple GUI applications, but can also develop complex applications as well.


• Programming in VB is a combination of visually arranging components or controls on a form , specifying attributes and actions of those components, and writing additional lines of code for more functionality.


• Since default attributes and actions are defined for the components, a simple program can be created without the programmer having to write many lines of code.


• Visual Basic is an event driven programming language and associated development environment from Microsoft for its COM programming model.


• Visual Basic enables the rapid application development (RAD) of graphical user interface (GUI) applications.

• Access to databases using DAO, RDO, or ADO is easy.

• Creation of ActiveX controls and objects are possible

Graphical User Interface

A graphical user interface (GUI) is a human-computer interface (i.e., a way for humans to interact with computers) that uses windows, icons and menus and which can be manipulated by a mouse (and often to a limited extent by a keyboard as well).

GUIs stand in sharp contrast to command line interfaces (CLIs), which use only text and are accessed solely by a keyboard. The most familiar example of a CLI to many people is MS-DOS. Another example is Linux when it is used in console mode (i.e., the entire screen shows text only).

A window is a (usually) rectangular portion of the monitor screen that can display its contents (e.g., a program, icons, a text file or an image) seemingly independently of the rest of the display screen. A major feature is the ability for multiple windows to be open simultaneously. Each window can display a different application, or each can display different files (e.g., text, image or spreadsheet files) that have been opened or created with a single application.

An icon is a small picture or symbol in a GUI that represents a program (or command), a file, a directory or a device (such as a hard disk or floppy). Icons are used both on the desktop and within application programs. Examples include small rectangles (to represent files), file folders (to represent directories), a trash can (to indicate a place to dispose of unwanted files and directories) and buttons on web browsers (for navigating to previous pages, for reloading the current page, etc.).

Commands are issued in the GUI by using a mouse, trackball or touchpad to first move a pointer on the screen to, or on top of, the icon, menu item or window of interest in order to select that object. Then, for example, icons and windows can be moved by dragging (moving the mouse with the held down) and objects or programs can be opened by clicking on their icons.

Advantages of GUIs

A major advantage of GUIs is that they make computer operation more intuitive, and thus easier to learn and use. For example, it is much easier for a new user to move a file from one directory to another by dragging its icon with the mouse than by having to remember and type seemingly arcane commands to accomplish the same task.

Adding to this intuitiveness of operation is the fact that GUIs generally provide users with immediate, visual feedback about the effect of each action. For example, when a user deletes an icon representing a file, the icon immediately disappears, confirming that the file has been deleted (or at least sent to the trash can). This contrasts with the situation for a CLI, in which the user types a delete command (inclusive of the name of the file to be deleted) but receives no automatic feedback indicating that the file has actually been removed.

In addition, GUIs allow users to take full advantage of the powerful multitasking (the ability for multiple programs and/or multiple instances of single programs to run simultaneously) capabilities of modern operating systems by allowing such multiple programs and/or instances to be displayed simultaneously. The result is a large increase in the flexibility of computer use and a consequent rise in user productivity.

But the GUI has became much more than a mere convenience. It has also become the standard in human-computer interaction, and it has influenced the work of a generation of computer users. Moreover, it has led to the development of new types of applications and entire new industries. An example is desktop publishing, which has revolutionized (and partly wiped out) the traditional printing and typesetting industry.

Despite the great convenience of the GUI however, system administrators and other advanced users tend to prefer the CLI for many operations because it is frequently more convenient and generally more powerful1. On Unix-like operating systems, GUIs are actually just attractive, convenient coverings for command line programs (i.e., programs which operate from a CLI), and they rely on them for their operation.

One of the great attractions of Unix-like operating systems is that they have maintained their CLI capabilities while continuing to improve their GUIs, thereby allowing advanced users to harness the full power of the computer while simultaneously making it easier for beginning and intermediate users. In contrast, the newer versions of Microsoft Windows (such as 2000 and XP) have downgraded their CLIs to marginal roles.