In VB, attributes can have parameters- that is: VB syntax, the use of parameters is not necessarily a method, there may be attributes! (Although the nature of the attribute is the method)
Example one: parameters used as "index"
Defines a class module, module name INTs. To simplify the model, read-only properties are used.
1 PrivateArr3) as Integer2 3 Public Property GetArrvalue (Index as Integer) as Integer4Arrvalue =arr (Index)5 End Property6 7 'Initialize the value of arr (3)8 Private SubClass_Initialize ()9Arr0) =1TenArr1) =2 OneArr2) =3 AArr3) =4 - End Sub
Call:
1 Sub Test () 2 Dim as New Ints 3 Debug.Print C.arrvalue (2) 'arrvalue is an attribute with parameter (index)4 ' Output =35End Sub
Example 2: Optional Parameters
Defines a class module, module name mycal.
The function of this class is to calculate the addend of two numbers, and to make Addend = 0 when the number is negative (example uses, not much practical meaning)
1 PrivateM as Integer2 PrivateN as Integer3 4 Public Property GetIntm () as Integer5Intm =m6 End Property7 8 Public PropertyLet Intm (ByValXvalue as Integer)9m =XvalueTen End Property One A - Public Property GetIntnOptionalB as Boolean=False) as Integer -INTN =N the End Property - - 'when Addend is negative, n is assigned a value of 0 - Public PropertyLet Intn (OptionalB as Boolean=False,ByValXvalue as Integer) + IfB andN <=0 Then -n =0 + Else An =Xvalue at End If - End Property - - 'calculates the two-digit and - Public FunctionMySum () as Integer -MySum = Intm +INTN in End Function
Call:
1 SubTest ()2 DimC as NewMyCal3 4C.intm =45C.INTN =-46 7Debug.Print C.mysum'Output 08 9C.intm =4TenC.INTN (True) = -4 One ADebug.Print C.mysum'Output 4 - - End Sub
The value of a Range object in VBA is a property with optional parameters
Another property of the Range object, Value2, is the non-parameter property
Meaning of the Value property parameter:
The parameter of the attribute in the VB class module--vba The Value property of the Range object and the Value2 property