Friday, January 22, 2010

Say hello to VB6

If you already have Visual Basic 6.0 (or the portable one) then let's get it on!!!

When you run VB 6.0, you'll be presented with a screen containing the available projects you can make, like this one:

For now, we'll just be concerned and working on the "Standard EXE" project (default selection). So just click on "Open" button to start our first project.

Now you'll get to Visual Basics IDE (or Integrated Development Environment)
Although it contains a lot of icons and menus, we'll just worry about some of them.

The menu bar is on top and has the text-based "pull-down" menu and the icon-based menu (most of the items in the text-based and icon-based are identical. For example, the diskette icon is used for saving the project, and you can also save from the "File" pull-down menu.

The Toolbar is where you get the controls from. These controls can be placed on the form (see the center image with "Form1"?). You can click on a control from this toolbox, then "draw" it on the form. You can try it now if you want :)

Another important location of the IDE is the Project window. This is where the project modules are located. VB 6.0 has three major modules : form module, basic module and class module.
We're just gonna work on the form module for now.

The form and the controls (from the toolbox) have properties as most objects do. A student for example has the "student id" property. A student could also have a "course" property, etc.
The "Form1" on the top is the "Caption" property of the form (default highlighted).
If you change the value to "My Form" or anything you want, then you'll see that it will change.

The immediate window is a debugger window but we won't be discussing it this early.

Next, let's take a look at the project window (top-right). You have two basic views: the "code" view and the "object" view. As the name implies, "code" view enables you to view the code of the module (in this case the form module). The "object" view is the view of the form and all the controls in it.

The toolbox is almost always used since this is where you get the form decorations.

The most commonly used controls are:

- Label
- Textbox
- Command button

and later we'll be using these controls:

- Directory (or dir)
- Drive
- File
- Image

For now, you can select any control and just place it on the form just to get you familiar with putting controls on the form. Try also to "align" or place them nicely so that your form layout looks good enough.

Next we'll take a close look at the Properties window.

It is a "visual" representation of the properties of the controls and forms. I said "visual" because you may also access these properties from inside the code.

There are basically four parts of it that you'll be using:

The object name is what is currently selected. In this case the form object. When you click on a control in the form, this value changes (ex. Textbox1, Label1)

The property name is (of course) the name of the objects property. Like we said, a form has "Caption" property, "Height", "Width", etc.
The value is also there for you to edit. Then the description is shown below, a summary of what the property does or what it's for.

Okay, go back to "Object view" to see the form. Then double-click on the form (the large gray area of it). You should be taken to the "code" view.
Alternatively you can also go this via the "code" view button (as discussed in the Project window)

See below for the basic parts of the code view:

The object list contains the form and other objects that you have on a particular module. The method and property list changes depending on what object is selected.

The block of code is where you type the commands you want to happen when a property or "event" takes place.

Now, you're ready to code. Inside the code block "Form_Load()" type 'MsgBox "Hello world" then click on the "run" button. See image below:

You should now see the output of your first program:

When you click on "OK", the form (Form1) will be displayed.

Well, that's it. This is your first Visual Basic application. This is not that great, nor does it do anything fancy but it's a program nonetheless.

You may go back and review, try to re-do what we have done (without looking at this) and make sure you are familiar with the IDE, where the controls are located, how to change a property value, how to enter and change code and run the program.

The next post will present another application so be sure you practice well :)

Thanks for viewing, happy coding for now!

Sunday, January 17, 2010

Welcome to tutorials!!!

This is my blog to teach programming using Visual Basic 6.0. My target audience are beginners and old school programmers and this is also the language I'm most familiar with.
If you already are programming then most of the lessons will be obvious and familiar to you so you can probably skip them or just read on to see if there are some ideas I introduced that might be of use to you.
I would assume from the start that the reader has no programming experience but at least is familiar with computer operations like web browsing, sending/receiving emails, probably even used office suites like Ms Office and/or OpenOffice.

If you don't have a Visual Basic editor, you can try the link below:

I don't own it, I just saw it while googling and wanted to share with you.

This will be useful so you can do the sample codes I will be posting and to try out what you have learned.