Microsoft Visual Basic - Introduction to VB
Logo

The Microsoft Visual Basic Environment

 

Microsoft Visual Basic

 

Introduction

Microsoft Visual Basic is a development environment used to create programs or applications for the Microsoft Windows family of operating systems. To do this, it uses a computer language that was originally called Basic but has been transformed in an advanced language also called Visual Basic. This language makes it particularly easy to create effective applications because it offers a working tool as a studio equipped with necessary materials to keep you moving.

Microsoft Visual Basic ships in three packages and sometimes various formats. The way you launch it depends on how it was installed. We will first analyze the studio and review some of its equipments, and then we will start creating small applications.

Starting Microsoft Visual Basic depends on how it was set up on your machine. If it were installed as a stand alone product, it would be available under the Programs menu; otherwise, it might be under the Microsoft Visual Studio group of applications. However it was installed, now is the time to launch it.
 

Integrated Development Environment (IDE)

  1. To launch Visual Basic, on the Taskbar, click Start -> (All) Programs -> Microsoft Visual Studio 6.0 -> Microsoft Visual Basic 6.0
  2. When Microsoft Visual Basic starts, the New Project dialog box comes up:
     

     
    At this time, we will not go through what all these icons mean. Just make sure that the Standard EXE icon is selected and click Open
  3. A typical studio such as the one used by Visual Basic is referred to as an Integrated Development Environment (IDE).
    As a classic application, Microsoft Visual Basic displays a title bar on top. The title bar is mainly made of three sections.
    On the most left side, there is the application icon. This icon has a menu of its own. To see the menu, click the small icon and click Maximize (or Restore)
  4. On the right side of the application icon, the name of the file allows to identify what you are working on. Microsoft Visual Basic names each one of its applications a project.
    A Project is a collection of files used to build a particular application. When Visual Basic starts, it calls the first application Project1. When you save a project, you give it an appropriate name, and the name on the title bar gets updated.
    On the right side of the Project1, the name helps to know what environment you are using to build your application.
    The Microsoft Visual Basic name is followed by the empty area of the title. This area can be used as a menu to maximize or restore a window.
    To experiment with it, double-click the empty section of the title bar. Notice that the window has been maximized (or restored) again
  5. The last three buttons on the title bar are used to perform windows operations. Every one of the buttons has a name. To find out a button's name, position your mouse on top of it and a name will appear.
    To experiment with the buttons, click the Minimize button
  6. To bring back Microsoft Visual Basic, on the Task bar, click Project1.
  7. Under the title bar, you have a menu made of words such as File, Edit, View, etc. These allow you to perform almost any kind of operation. To use a menu, you click one of the words. A menu drops down and you make another selection from it.
    We need to review how a menu functions because as a programmer, you will have to create a menu or menus sooner or later.
    There are typically four kinds of menus here.
     
    Disabled Menu A disabled menu is a menu that is temporarily unavailable. This could be due to anything. For example, it might wait for another action to happen. Sometimes, there might be something running on the background and this would disable a function of your program or the application.
    To view an example of such menus, on the main menu, click Edit and observe a lot of disabled menus.
    To see another, position the mouse on Diagram and notice that the whole Diagram menu is disabled.
  8. Enabled Menu An enabled menu standing by itself will usually perform a brief action, sometimes leaving the impression that nothing happened. This kind of menu can be used to quickly save a file, display a toolbar, etc.
    To see an example, on the main menu, click Edit -> Copy. It looks like nothing happened. The form (or if anything else was selected) has been copied to the clipboard, which is a temporary storage area of your computer.
  9. To see another kind, on the main menu, click View -> Locals Window. Notice that there is a new section on the screen now.
  10. Menu With Three Dots A menu with three periods (…) is typically used to launch or open a dialog box.
    To experiment with it, on the main menu, click Tools -> Options… Notice that the Options dialog displays.
  11. The Options dialog is made of various property sheets. Click the Editor Format property sheet.
    From the Code Colors list box, click Normal Text. Click the Foreground combo box and select a green color.
    From the Code Colors list, click Selection Text. Click the Foreground combo box and select blue. Click the background combo box and select the lime color

    Options Dialog Box
  12. Click Comment Text. Click the Foreground combo box and select dark gray.
    Click Keyword Text. From the Foreground combo box, select blue.
    Click Identifier Text. From the Foreground combo box, select pink.
  13. Click OK. At this time, we cannot yet experiment with the new settings.
  14. Parent Menu A menu with an arrow indicates that it has a sub-menu, which is a child menu.
    To see an example, on the main menu, click View -> Toolbars. Notice the items under the Toolbars menu.
  15. To see another menu like that, position the mouse on Format -> Center In Form.
  16. Whenever a menu is opened but you don't want to use it, you can dismiss it with the Esc key.
    To dismiss the current menu, press Esc. Press Esc again.
  17. Some menu items present a key or a combination of keys on their line: this is called a shortcut. A shortcut is a key or a combination of keys that allows you or the user to perform an action quicker than using the menu.
    Some shortcuts can be seen on the menu of Visual Basic. Some other shortcuts are part of Microsoft Windows operating systems.
    To see a list of some of the shortcuts, on the main menu, click Edit. Observe the list of shortcuts and the actions they are associated with.
  18. Press Esc to dismiss the menu.
  19. To use a one-key shortcut, just press the corresponding key. For example, press F5. Notice that the form changes its looks. Actually the form went from its design state to its running state.
  20. To close the running form, click its close button .
  21. To use a combination of keys, press the first key (or one of the keys), and then press the other or others. Finally release the keys.
    To experiment with other shortcuts, press and hold Ctrl, then press F5. Notice that the form runs again as an application.
  22. To close the running form, since it is treated as a complete application, press Alt + F4.
     
    Some other shortcuts are part of the operating system. For example, Ctrl + Esc would open the Start menu; Alt + F4 is used to close applications.
  23. Under the menu, there is a toolbar. This first toolbar is called the Standard toolbar.
    The Standard toolbar allows you to perform many of the most common actions that would require the main menu, except that the toolbar is handier and closer to the user, which makes it faster.
    A toolbar is made of buttons that you click to perform the corresponding action.
    At first, nothing is obvious with these buttons. Therefore, to find out what a particular button is used for, position your mouse on top of it and keep it there for 2 seconds. A word and group of word will appear: this is the tool tip, allowing you to identify the button. The buttons are usually named after their tool tip.
    To get acquainted with some of the buttons, position your mouse on the first button for 1 or 2 seconds and observe the tool tip.

    Tool Tip
  24. Move the mouse to another button and read the tool tip.
  25. To experiment with one of the button, on the Standard toolbar, click the Start button Start. Notice that the form runs in its execution state.
  26. To stop the running form, on the Standard toolbar, click the End button End.
  27. Some of the buttons on the toolbar have an arrow on them. This indicates that the button, behaving like a menu or a combo box, can display more items when you click its arrow.
    To see an example, click the arrow of the Add Form button. Notice other items available.
  28. Without clicking, move the mouse to the arrow of the first button on the toolbar, the Add Standard EXE Project button.
  29. To dismiss the menu, click the arrow of the same menu.
  30. The main area of the studio is made of a rectangular box called a form and is typically identified as Form1; if you create additional forms, by default, they would be identified as Form2, Form3, or FormX.
  31. The Toolbox provides the necessary tools to create your applications.
     
    Microsoft Visual Basic Toolbox The Toolbox comes with a lot of controls to start working. It can also be enhanced with more objects that we will review as we move on.
    Like the items on the Standard toolbar, the controls on the Toolbox are not always obvious. To find out what kind of control is displayed, position your mouse on a control and observe the tool tip. Review different items until you find the one you want.
    To use a control from the Toolbox, click it and draw it on your form. When no object is being used, the Pointer is selected. Once you select one of the controls, the pointer loses focus and you can use the selected control.

    We will learn how to use the controls in another lesson.

    Notice that the right section of the Standard toolbar displays the dimensions of the form.

  32. The Properties Window displays a list of the properties associated with each control or form that are part of your project.
    A property is anything that characterizes an object. When you look at a control, you see that it has a size, a color, a caption (something written on some controls; for example, on top of the form, the caption is Form1), etc.
    Different controls have different sets of properties.
    To experiment with controls properties, on the Properties Window, click the (Name) field and type frmTimeSheet
    Notice that even though you clicked (Name), the name has been changed.
  33. Click the Caption field and type: Time Sheet
  34. The Project Explorer window gives a list of the forms and modules that are part of the current project.
     
    Project To experiment with the Project Explorer window, click the Toggle Folders button Toggle Folder. Notice that the folders are collapsed.

    To expand the folders, click the Toggle Folders button again.

     
  35. Still on the Project Explorer window, click View Code. You are presented with the Code Editor window.
  36. To send the Code Editor window to the background again, on the Project Explorer window, click the View Object button View Object.
     
  37. The Form Layout window allows you to position your form or forms with regard to the rest of the screen. It uses a graphical interface to guide you.
    To experiment with it, click the small image inside the small screen and drag to the upper left corner inside the small screen. Notice that the small image can move.
    Form Layout
     
  38. Drag the small rectangle in the Form Layout screen again and position it to the middlw of the small screen.
  39. To verify the result, press F5 to run the form. Notice that the running form displays in the center of the screen.
  40. To close the running form, click its close button.

Saving a Project

A program you create in Microsoft Visual Studio (of course, this includes VB) is called a project. A Microsoft Visual Basic project is made of various objects that you create or add as your program grows. Therefore, when saving a program, you have to save the main project and its objects.

There are two categorical pieces of information you should provide when saving a program: the project's location and a name for each object or file. The location is a folder where you store the program for easy retrieval when needed. A name for each component allows you to identify it as compared to other objects of the same program. An object's name can contain a combination of up to 255 characters. Refrain from using fancy characters. Assign a name made of characters a to z, A to Z, and digits 0 to 9.

 

Saving the Project

  1. To start a new project, on the main menu, click File -> New Project
  2. In the New Project dialog box, double-click Standard EXE. If you are asked whether you want to save the project, click No
  3. To save the current project, on the main menu, click File -> Save Project
  4. Click the arrow of the Save In combo box and select the C: drive
  5. On the Save File As dialog box, click the Create New Folder button Create New Folder
  6. Type MS Visual Basic and press Enter twice to display the new folder in the Save In combo box
  7. Click the Create New Folder button Create New Folder again
  8. Type Exercise1 and press Enter twice to display the new folder in the Save In combo box
  9. In the File Name edit box, change the name of the file to frmMain and press Enter to save the file
  10. Change the name of the project to Exercise1
     
    Save As
  11. Click Save. Depending on your package (or no package) of MS Visual Studio, you may be asked whether you want to add this project to Source Safe; if you are prompted so, click No
  12. Close Microsoft Visual Basic
 

Copyright © 2001-2004 FunctionX, Inc. Next