Setting-up the environment
Visual Basic 2008 Express Edition
Visual Studio 2008 is a very complete and complex product. It's great if you're a professional developer writing commercial apps, integrating several languages and using advanced Web tools and so on.
But if this is your first experience with VB or if you want to explore a move up to 2008 after working in VB 6 for years, you may not need all the power of the full VS package.
Fortunately, Microsoft offers a simplified version which can be downloaded for free and will allow you to do all the tutorials we present here. The product is called Visual Basic 2008 Express Edition.
You can download it from the Microsoft Express site.
You'll need to register the product but it is free to use. All our VB 2008 tutorial examples were written with Express Edition and it is totally sufficient for all but the most advanced users.
Customize the IDE
When you install VB 2008, all the default options are usually pretty much set for you.
There are a couple of options you may wish to look at.
Interface with the user
The Form is the first object you work with in VB.
It is the primary interface with the user. It is used to input DVD rentals in the Video store application or customer data in your on-line Dating Service.
The form can even be your game surface if you're learning programming with the hope of becoming the next great game designer.
When you design the form you have to take into account the user's requirements - the video rental store will have a different operating environment from the online pharmacy or the poker game you're creating. For example, any kind of game will probably require timers but most business applications never use them.
Before you even begin to work in VB, you should take a few minutes to think about the layout of the form. You can even draw a sketch of what you expect to produce. You will identify the size of the objects, the placement, the colors.
Start with a blank form.
All the objects you put on a form are called controls. You get them from the Toolbox on the left. You click on a control in the toolbox and then drag the cursor on the form where you want the control to be.
Draw a label on the form. Then add a button and another label.
Now, you're working with 4 objects: the form and 3 controls: 2 labels and 1 button.
The first, and easiest thing to change is the color of all the controls.
So, you click on an object to select it and you go over to the Properties window and select a color for Backcolor.
Do this for all 4 objects.
Some of the properties are common to most objects. These are the ones you normally set at design time.
- BackColor - background color, the color of the object
- ForeColor - foreground color, the color of the text
- Font - the font type, size and style for the text in the object
- TextAlign - position of the text in the object - upper left, middle, etc.
- Text - the text that appears in the object - sometimes it's fixed (titles, captions) but usually, it changes at execution time
Running the application
If we want the app to do something, we have to program it, ie: write code.
In VB, the app is event-driven - the code is executed when some event occurs. In this case, the event is the Click of a button.
To get an idea of how this works, double-click Button1. This will open the code editor and will generate a subroutine. The Sub is identified by the first line of Private Sub ..... and ends with End Sub.
Then, write the code shown inside the Sub.
Or, download the sample containing what we've done so far.
Just extract the application into your VB folder.