Introduction to VB: Objects & Controls, Properties, Events, Methods

Chapter #2: Properties

We talked a litle bit about properties on Chapter #1. But there are a few more things we could discuss. Enough of coffe cups, lets talk VB! When you run the IDE (Internal Development Environment - The program where you write and design your VB-Software) at first youīll want to make some experiments with the basic project, the 'Standard EXE'. You will get a token main form that will be named automatically 'Form1' and will follow the rules of the main properties definition by the class "Forms". A form will have the following properties:

Appearance
AutoRedraw
BackColor
BorderStyle
Caption
ClipControls
ControlBox
DrawMode
DrawStyle
DrawWidth
Enabled
FillColor
FillStyle
Font
Height
Icon
Image
KeyPreview
Left
LinkMode
LinkTopic
MaxButton
MinButton
MouseIcon
MousePointer
Moveable
Name

And lotīs of others...
Letīs talk about 'Name' and 'Caption'. In the example in chapter #1, we had a "Cup1" with the caption set to "Dadīs".

Thereīs a difference between how the programmer (you) will refer in the code section to the object, and how will the user know the object (Dad). That is, you will know that you have a cup lying on Table1 that was named "Cup1". You will refer to it as "Cup1". You will have in mind that the refereable name of this object is "Cup1" only. BUT! the user will get know the cup (when the cup+the table+the coffeepot+etc are compiled in a .exe) as "Dadīs". He would rather tell you: "The 'Dadīs' cup doesnt accept tea! why?". Well, you canīt just tell him that "Cup1" is a member of the class "CoffeeCups", thatīs why methods coming from the class "TeaPots" wonīt do effect on it... You should say something like "Wait for the upgrade, v2.0 will have a "Dadīs coffee" and a "Dadīs tea" so you can have any of both, even at the same time without crashing your table"...hehee

You must understand that controls have two totally different properties: 'Name' and 'Caption'

Caption can be anything you want. (anything you can type with a regular 101-102keys keyboard). But the 'Name' of the object must follow some rules. For example, you canīt give a Form Object the name 'Type', because that is a reserved word from the language to do other things, or name your Form 'myFormX$' that is an identifier or variable. Thatīs no way to name a Form...
You can accept the autovalues of Form1/Form2/Form3/etc or name your forms to something more representative, for example:

frmMain
frmOpen
frmClose
frmHelp
frmGoodBye

But thereīs a difference between what you show to your user as the "Caption" of the window and the real name that you gave it while coding.

Properties are variables. As variables, they have value types:

Name & Caption are strings
hWnd is a Long Integer
Left & Top are Short Integers (the x/y pos of the control)
Enabled is a boolean (can only be 'True' or 'False')
ForeColor is a Hexadecimal value
Tag is a multipurpose variant. It can be anything, an integer, a string, a long... whatever.

Before continuing I will present you the two 'scenarios' of VB coding (drum suspense....):

D E S I G N T I M E / R U N T I M E

Now, what is that?!

Design time:
            Takes place while you are at the IDE, and are adding controls to your form, adding more forms, typing code on the forms code-sheet, more controls, more code, more forms, more code, more code, commenting some lines, deleting other, adding a picture to a button, assigning an icon to a form, etc, etc, etc...

In "design time" some properties are not available, because they are dinamic properties that are assigned by the operative system or other events that canīt be handled within design time.

As an example of such:

hWnd : short for handleWindow, or "Handle to the Window". This is a Long Integer number assigned by the operative system to uniquely identify the window. Every time your program runs, every form (and control) in it are assigned a new hWnd number. There are APIs that report those numbers, or can find a window if you know its hWnd.

Run Time:
            Starts to happen as soon as your program is running. If you didnīt compile it yet, and you are doing a test from the IDE, youīve pressed F5 or clicked on the 'play' icon (>) you are 'at runtime', until you stop your program, or your program stops itself by reaching an "END" statement. If the program is a .EXE already, run-time is happening all the time, while the program is running right there in your screen. At 'run-time', some properties can be altered, and some not.

As an example of such:

Name : The name with-in the code. It is automatically set by the IDE to a control when you addit to the project (ie.: Form1, Command1, Project1) but you can change it at design time to something more representative. BUT when you are already at run-time controls, forms and others have the name that was given at design time and it canīt be changed. It can be read, and some logical operations can be done by it, but it canīt be changed. This is known as "Read-only at run-time" properties.

Another constitutive part of an object are its events. That will be explained on the next chapter.


Back up to the Index