Using Class Modules StatusBar
Apart from the modules to have Excel VBA code, there are also class or Class Modules Modules, these modules can create custom classes for which can be represented in some form objects, but Excel VBA is not a language-oriented objects, you can take advantage of some advantages that the use of classes.
To illustrate the use of classes, craft class Rectangle . In general aspects a class has a constructor, private variables, methods of reading / writing of private variables, properties and methods themselves. In a class module builders no more if Initialize event class, a private variable is created with the private ruling to define a variable, property, reading / writing is performed using keywords and Get Let the Property properties and methods as other Sub or Function.
Here is the code for the Rectangle class, then I will explain what each thing.
The code, first variable is declared private (pnombre, pancho, plargo), then the event has delcarado initialization of a class (Class_Initialize), which should not declare parameters for the class rectangle (length, width) automatically takes the values \u200b\u200bstated Initialize.
then declared the properties of read / write access (Get / Let) to each of these variables. Then said the Area and Perimeter properties that are calculated based on the parameters plargo and pancho. Finally, set the Resize method, which resets the size and pancho plargo a percentage f. Taking
active sheet write the following (see figure):
Then in a normal module add the following sub.
Note that two objects are declared and oRec2 oRec1 rectangle, the first takes data from C3 and D3 on the active sheet, while not making any value oRec2, maintains the values \u200b\u200bgiven in Class_Initialize to plargo and pancho. These values \u200b\u200bare written on the sheet, then adjust oRec1 the Resize method and values \u200b\u200bare inscribed on the sheet. Run readRectangulos to see results, you can download the file here .
In the next post mention about using custom class collections. Good luck.
0 comments:
Post a Comment