| Adding to the System | |
| 2 - The Parts Are Greater Than The Whole | |
|
A core idea of OOP is that you shouldn't have to write the whole program yourself. You should be able to take advantage of objects that have been written by other programmers! We followed that idea in one direction by using objects that are part of Word and Visual Basic to create the code we have so far. In this segment, we follow it in another by including another category of objects that also go by the names components or controls. The best way to illustrate controls is to show you where the main group of them can be found: In the Visual Basic Toolbox. This group of controls is common to just about every Visual Basic environment you will see and form the basic building blocks of most applications. You use them by simply dragging and dropping them onto a Form in your Visual Basic application, or even right into the document itself. After you have completed a few Visual Basic systems, you will know them like old friends! In the next segment, We will add controls to the FormLetter macro by placing them on a UserForm. In this segment, we're just learning about controls in general. You may want to return to this segment and review it after a Form has been added. To learn about the controls, let's look at one in more detail: the popular ComboBox. The controls that we use in the next segment work about the same way. Most people find it very easy to add controls to a Form and adjust their size and position by dragging on the control and the sizing handles with the mouse. Figuring out how to use all the properties for controls is where the real work starts. For example, there are fifty properties for the ComboBox that can be set for different purposes. The first property of a control that you will want to change is the name. Since VB 6 has "weak data typing" - that is, variables can be used for virtually any type of data - most authorities recommend that you choose a name for controls that starts with a prefix that lets you know what it is when you're debugging your program. If you use a ComboBox for, say, account numbers, you might want to name it cmbAccountNum. The rest of the properties can usually be set by programming statements (at "run time") or in advance (at "design time"). For example, if you wanted to highlight a ComboBox at run time to alert the user, one way to do it would be: Note that these statements use built-in constant values to identify the colors. You can find a complete list of these using the Object Browser. Also note that I used the default name of the control ComboBox1 rather than changing it to something like cmbAccountNum since this is just an example. A ComboBox is a good example of a type of control that you can use as a place to store lists of information that your program needs. Some examples might be: As you can see, there are a lot of different kinds of information that work well with this control and that is one of the reasons it's used so frequently. With this introduction in mind, let's actually add some controls to our program in the next section: |
|

