The parameter of the attribute in the VB class module--vba The Value property of the Range object and the Value2 property

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.