Compartilhar via


Como: Chamar um procedimento de propriedade (Visual Basic)

You call a property procedure by storing a value in the property or retrieving its value. You access a property the same way you access a variable.

The property's Set procedure stores a value, and its Get procedure retrieves the value. However, you do not explicitly call these procedures by name. Você pode usar a propriedade em uma instrução de atribuição ou uma expressão, como você poderia armazenar ou recuperar o valor de uma variável. Visual Basicfaz as chamadas para os procedimentos da propriedade.

To call a property's Get procedure

  1. Use the property name in an expression the same way you would use a variable name. You can use a property anywhere you can use a variable or a constant.

    - ou -

    Use the property name following the equal (=) sign in an assignment statement.

    O exemplo a seguir lê o valor da Now propriedade, implicitamente chamando seu Get procedimento.

    Dim ThisMoment As Date
    ' The following statement calls the Get procedure of the Visual Basic Now property.
    ThisMoment = Now
    
  2. If the property takes arguments, follow the property name with parentheses to enclose the argument list. If there are no arguments, you can optionally omit the parentheses.

  3. Place the arguments in the argument list within the parentheses, separated by commas. Be sure you supply the arguments in the same order that the property defines the corresponding parameters.

The value of the property participates in the expression just as a variable or constant would, or it is stored in the variable or property on the left side of the assignment statement.

To call a property's Set procedure

  1. Use the property name on the left side of an assignment statement.

    O exemplo a seguir define o valor da TimeOfDay propriedade, implicitamente chamando o Set procedimento.

    ' The following statement calls the Set procedure of the Visual Basic TimeOfDay property.
    TimeOfDay = #12:00:00 PM#
    
  2. If the property takes arguments, follow the property name with parentheses to enclose the argument list. If there are no arguments, you can optionally omit the parentheses.

  3. Place the arguments in the argument list within the parentheses, separated by commas. Be sure you supply the arguments in the same order that the property defines the corresponding parameters.

The value generated on the right side of the assignment statement is stored in the property.

Consulte também

Tarefas

Como: Criar uma propriedade (Visual Basic)

Como: Declarar uma propriedade com níveis de acesso mistos (Visual Basic)

Como: declarar e chamar uma propriedade padrão em Visual Basic

Como: Inserir um valor em uma propriedade (Visual Basic)

Como: Obter um valor de uma propriedade (Visual Basic)

Referência

Propriedade declaração

Declaração Get

Declaração Set (Visual Basic)

Conceitos

Procedimentos de propriedade (Visual Basic)

Parâmetros e argumentos de procedimento (Visual Basic)

Diferenças entre variáveis e propriedades em Visual Basic