|
A template for building collection class modules
|
Total Hit (3650) |
The following is a template for building collection class modules in a very quick and effective way. Copy-and-paste this code into Notepad, that save it to a file named "COLLECTION CLASS.CLS" in the \TEMPLATE\CLASSES subdirectory under the main VB6 directory:
«Code LangId=1»
VERSION 1.0 CLASS
B
....Read More |
Rating
|
|
|
Better type checking in Variant properties that can accept objects
|
Total Hit (2915) |
As explained in the Mistake Bank you need all three flavors of Property procedures to correctly implement a Variant property that can take either an object or a non-object value. Surprisingly enough, in this case you don't need that the argument of the Property Set procedure be declared As Variant.
....Read More |
Rating
|
|
|
Default Properties tend to hide programming mistakes
|
Total Hit (2861) |
Visual Basic lets you create a default property or method by simply selecting the "(Default)" item in the combo box that appear if you click the Advanced button in the Procedure Attributes dialog box. (You can display this dialog from the Tools menu, or by right-clicking on a property name in the ri
....Read More |
Rating
|
|
|
Don't test auto-instancing variables using Is Nothing
|
Total Hit (2992) |
You can't reliably test an auto-instancing object variable using the Is Nothing test, because as soon as you reference the variable Visual Basic silently creates an object of the given class, and the test always returns False:
«Code LangId=1»
Dim x As New MyClass
If x Is Nothing Then
' this
....Read More |
Rating
|
|
|
Friend Procedures are faster than Public ones
|
Total Hit (3031) |
It might surprise you to learn that Friend procedures are sensibly faster than Public ones. You can prove this yourself by creating an ActiveX EXE project with one Private class and one Public class (Instancing = MultiUse), and then add the following code in both class modules:
«Code LangId=1»
P
....Read More |
Rating
|
|
|
Implement Write-Once Read-Many Properties
|
Total Hit (4080) |
Creating a read-only property or a write-only property isn't difficult, as you probably know: just omit the Property Let (or Set, if dealing with objects) or the Property Get procedure, respectively.
There are cases, however, when you want to implement a write-only-read-many property, that is, a
....Read More |
Rating
|
|
|
Passing Public class variables by reference
|
Total Hit (3002) |
Under VB4 Public variables in form and class modules were implemented in the same manner as variables in BAS modules, that is, as direct references to memory locations. This allowed VB programmers to create procedures that modified values passed by reference, as in:
«Code LangId=1»
'--- the CIn
....Read More |
Rating
|
|
|
Use Objptr function to quickly locate an object in a Collection
|
Total Hit (3198) |
One of the simplest and most effective uses of the ObjPtr function is to provide a key for quickly locating an object in a Collection. Let's suppose you have a collection of objects that don't have a property that can be used as a key to retrieve them in a collection. You can work around this by usi
....Read More |
Rating
|
|
|
|
Using CallByName with nested objects
|
Total Hit (3204) |
Sometimes Microsoft documentation can be, well lacking is a kind word, and one is reluctant to call tech support when they smoke your credit card first, and ask questions later.
My problem was that the CallByName procedure was refusing to call nested lasses. To see what I mean, consider that if y
....Read More |
Rating
|
|
|
|
|
|
|