Exercise 4 :: Overview
We now review the things we have looked at up to this point. We have been gradually learning ideas and techniques, and now we bring them together and show how it all fits together.
Programming concepts
Comments
Comments are used to add code that will not be executed. Comments begin with an apostrophe and will be shown in the IDE in green. More details can be found in Exercise 3.
Variables
Variables are used to store values. You declare a variable and then you can use it to store values that will be used during the execution of the program. We have used variables to take user input and then to perform some calculations with them. Variables are declared in VB with the Dim statement. More details can be found in Exercise 3.
If Statements
If statements allow you to choose between two possible sequences of execution depending on a conditional statement. If statements are vital to programming in any language, they are not specific to Visual Basic. More information on if statements is available in Exercise 3.
VB IDE
The Visual Basic IDE is the program that will drive all of your VB work. Everything you do in VB will be done with this incredibly useful program. For this reason it is a good idea to become really comfortable with this program. The basic things you should ensure you can do are
- Create a new project
- Save a project
- Create a standard executable
- Add controls to forms
- Use the properties pane
- Use the code editor
The VB programming language
Objects
Visual Basic is built around a loose object model. Everything in the VB "universe" is made up of objects. Forms are objects, controls are objects, everything is an object. You can use the "dot notation" to reference the members of an object. It is important for efficient programming in Visual Basic to have a reasonable understanding of the VB object model.
Special Functions
VB provides a number of special functions that make our programming lives easier. In particular, we have seen how to use the following functions
More details on this can be found in Exercise 3.
Coding conventions
To this point we have seen some useful VB code and even written some usable VB programs, now we will consider the issue of coding conventions. Coding conventions are not part of the language, they are simply suggested guidelines to help make your programming easier. VB has a widely accepted set of coding conventions that go into quite a bit of detail. We will worry only about a few of the more important guidelines. Remember, these are not rules, merely suggestions.
- controls should be named with a three letter prefix indicating what kind of control it is. For example, a command button that cancels should be called cmdCancel
- command box - cmd
- text box - txt
- frame - frm
- radio box - opt
- label - lbl
- check box - chk
- picture box - pic
- etc.
- name controls and variables with the the first letter of each word (except the first) capitalised. For example, a variable for "number of people" would be named numberOfPeople.
There is one feature of the language that looks a lot like a coding convention. The procedures to go with each event are in the form object_Event(). However, this is a rule and makes it easy to find the code to go with each event.
The object browser
The object browser can give you information about all the objects in the VB universe. It will also tell you all the methods and properties available for these objects. To access the object browser go to "View->Object Browser" or just press F2.
NEXT ->
Matthew Roberts, Macquarie University 2002