Minggu, 28 Maret 2010

Getting Started with Visual Basic 6.0

Visual Basic is initiated by using the Programs option > Microsoft Visual Basic 6.0 > Visual Basic 6.0. Clicking the Visual Basic icon, we can view a copyright screen enlisting the details of the license holder of the copy of Visual Basic 6.0. Then it opens in to a new screen as shown in figure 1 below, with the interface elements Such as MenuBar, ToolBar, The New Project dialog box. These elements permit the user to buid different types of Visual Basic applications. 

The Integrated Development Environment

One of the most significant changes in Visual Basic 6.0 is the Integrated Development Environment (IDE). IDE is a term commonly used in the programming world to describe the interface and environment that we use to create our applications. It is called integrated because we can access virtually all of the development tools that we need from one screen called an interface. The IDE is also commonly referred to as the design environment, or the program.

Tha Visual Basic IDE is made up of a number of components

  • Menu Bar
  • Tool Bar
  • Project Explorer
  • Properties window
  • Form Layout Window
  • Toolbox
  • Form Designer
  • Object Browser
In previous versions of Visual Basic, the IDE was designed as a Single Document Interface (SDI). In a Single Document Interface, each window is a free-floating window that is contained within a main window and can move anywhere on the screen as long as Visual Basic is the current application. But, in Visual Basic 6.0, the IDE is in a Multiple Document Interface (MDI) format. In this format, the windows associated with the project will stay within a single container known as the parent. Code and form-based windows will stay within the main container form.


                                                  picture : the visual basic startup dialog box


Before you start to build-up the form, it will make it easier if you change the color of the form. Otherwise you will be working with grey controls on a grey background. To change the color, just click anywhere on the form, go to the properties window, find the property called BackColor and change it to the standard Window background (teal) or to any color you want in the palette.

In our first example we will need 6 labels and 2 command buttons. Each one of these objects that you put on a Form is called a control. To get a control you go to the Toolbox, click on the control you want, come back to the Form and click and drag the control to the size and position you want. Position the controls somewhat like in the diagram below.

                                                         picture : visual basic form

Menu Bar

This Menu Bar displays the commands that are required to build an application. The main menu items have sub menu items that can be chosen when needed. The toolbars in the menu bar provide quick access to the commonly used commands and a button in the toolbar is clicked once to carry out the action represented by it.

Toolbox

The Toolbox contains a set of controls that are used to place on a Form at design time thereby creating the user interface area. Additional controls can be included in the toolbox by using the Components menu item on the Project menu. A Toolbox is represented in figure  shown below.

                                picture : Toolbox window with its controls available commonly


  • Pointer               Provides a way to move and resize the controls form
  • PictureBox          Displays icons/bitmaps and metafiles.
  • TextBox             Used to display message and enter text.
  • Frame                       Serves as a visual and functional container for controls
  • CommandButton        Used to carry out the specified action when the user chooses it.
  • CheckBox                  Displays a True/False or Yes/No option.
  • OptionButton              control which is a part of an option group allows the user to select only one option even it displays mulitiple choices.
  • ListBox                      Displays a list of items from which a user can select one.
  • ComboBox                 Contains a TextBox and a ListBox. This allows the user to select an ietm from the dropdown ListBox, or to type in a selection in the TextBox.
  • HScrollBar and VScrollBar               These controls allow the user to select a value within the specified range of values
  • Timer                         Executes the timer events at specified intervals of time
  • DriveListBox               Displays the valid disk drives and allows the user to select one of them.
  • DirListBox                  Allows the user to select the directories and paths, which are displayed.
  • FileListBox                  Displays a set of files from which a user can select the desired one.
  • Shape                          Used to add shape (rectangle, square or circle) to a Form
  • Line                            Used to draw straight line to the Form
  • Image                         used to display images such as icons, bitmaps and metafiles. But less capability than the PictureBox
  • Data                            Enables the use to connect to an existing database and display information from it.
  • OLE                           Used to link or embed an object, display and manipulate data from other windows based applications.
  • Label                           Displays a text that the user cannot modify or interact with.

- - -  Next
»»  read more

Part I : Introduction


About VISUAL BASIC 6

Visual Basic 6 is not your grandfather's BASIC! If your knowledge of programming is limited to the QBASIC you toyed with in high school, you'll think you've landed on a different planet. You may still see the occasional GoTo hanging around but, for the most part you will be in unfamiliar territory. For one thing, the word Basic in Visual Basic is not an acronym anymore. It used to be. When the language was invented in the early 70's, BASIC stood for Beginners' All-purpose Symbolic Instruction Code, thus the acronym (word formed from the first letter of several words, in upper-case). It is certainly not just for beginners, and although it is quite versatile, I don't know if I'd call it exactly All-purpose. And while it is still Instruction Code, it is more than Symbolic now. But THE big difference is the Visual aspect of it where you work with windows and icons and pictures and multimedia. 

Visual basic is a high level programming language developed from the earlier DOS version called BASIC. Though, Visual Basic .NET is the latest technology introduced by Microsoft with tons of new features including the .NET framework and educational institues, Universities and Software Development companies have migrated to VB .NET, Visual Basic 6 is still widely learned and taught.

Learning Visual Basic 6 is quite easier than other programming languages such as C++, C#, Java etc. This is because Visual Basic enables you to work in a graphical user interface where you can just drag and drop controls that you want to work with where you have to write bunches of code to create in C++ or C# or even in Java. If you are new to programming and want to start it in the smoothest and easiest way, then you should start it with Visual Basic.

Before you start developing a Visual Basic 6 application you should be aware that some programming knowledge is useful. If you have used BASIC or Pascal or C before you got here, that's OK. If you did learn one of those languages, you were working in a procedural fashion: when you type RUN the program starts at the beginning and basically follows the instructions going down the list, skipping here and there according to control instructions until it finds some kind of END statement. That is not how Visual Basic operates. Rather than procedural it is event-driven. There will be more on that subject in the next lesson.

However, you do have to write Visual basic 6 code to program the events - there are loops and conditions and arrays. We will not be covering the fundamentals of programming as such - you should be familiar with the basic constructs such as the IF...THEN...ELSE or the FOR...NEXT statements.
versions
You may be aware that there are several dialects of the Visual Basic language in use. This tutorial is on standard Visual Basic. It uses the VB IDE (Integrated Development Environment) to let you create standalone Visual Basic applications that can be distributed as .EXE files. Visual Basic for Applications (VBA) is the language used to tie Microsoft Office products together. It links Word and Excel applications, for example. Although it is very similar to standard VB, it does have several particular techniques that must be learned on their own. VBScript is a small subset of Visual Basic, with limited instructions, mostly used in Internet applications.

As for version, this tutorial is based upon Visual Basic 6.0. You may have access to version 4 or 5 in your environment. Don't worry about it. Of course Mr. Gates would like us to rush out to the store and buy the latest release as soon as it hits the shelves but we are not all as, shall we say, fortunate, as Mr. Gates when it comes to spending money. Right now, when a new version is announced, most of the improvements cover Internet access or Class libraries, etc. At this level of training, we will not be using most of those facilities and so, one version is just about as good as another. A form is a form and a button is a button. There may be slight differences in the interface between versions but those will not matter much.

The only problems occur when you try to run an application on a lower version of the software. It normally doesn't work. But the hardest part of creating an application is usually in writing the code. Some scripts can run into the 100's of line. Fortunately the script is just text and you can work around the version problem with Cut and Paste operations. You will have to redraw the forms, buttons and so on but, that is a minor inconvenience when you can paste in the code for all those objects.

In order to be as accessible as possible, the code downloads at the end of the tutorial will all be in the form of text files that can be pasted into any version of VB.

Visual Basic .NET is now available. Although very similar in most ways to Visual Basic 6, Visual Basic .NET does have significant differences in its approach. For one thing, VB .NET is now completely object-oriented, which isn't the case with Visual Basic 6. An application that runs well in VB 6 will have to be converted, using a conversion wizard to run on VB .NET. Microsoft tell us that the conversion wizard will convert 95% of the code (an optimistic estimate?). Regardless, that leaves at least 5% that will have to be converted manually. That means that a lot of people will wait to see further improvements before jumping to the new version. And add to that the fact that Visual Studio .NET, the parent framework for VB has a huge infrastructure. It requires lots of system resources. For example, you need at least 128 meg of RAM. Excuse me! When I look at the real world I see thousands upon thousands of perfectly good computers with less than 128 meg of memory.

However, if you are just getting into programming or into VB, the basic stuff doesn't change. You still need to know how to create a form, how to put controls on a form, how to write a loop or a decision structure. That hasn't changed in ages and that you can still learn with Visual Basic 6. I see installations out in the real world still doing tons of interesting work with versions 4 or 5 of Visual Basic!
»»  read more

image2

»»  read more

image1

»»  read more
 

flagcounter

free counters