添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

宣告構成 Property 程式 主體的 名稱、自 變數和程式代碼,其會將值指派給 屬性 。

[ 公用 | 私人 | Friend ][ Static ] Property Let name ( [ arglist ], value )
[ statements ]
[ Exit 屬性 ]
[ statements ]
End 屬性

Property Let 語句語法包含下列部分:

每個 Property Let 語 句都必須為它所定義的程式定義至少一個 有效的 自變數。 ' valid ' 表示不應該使用 'Optional' 或 'ParamArray' 來修改它。 該自變數 (或最後一個自變數,如果有多個) 包含叫用 Property Let 語句所定義的程式時要指派給屬性的實際值。 在上述語法中,該自變數稱為 值 。

如果未使用 Public 、 Private 或 Friend 明確指定,則預設會公開 屬性 程式。 如果未使用 Static ,則不會在呼叫之間保留局部變數的值。

Friend 關鍵詞只能用於類模組。 不過, Friend 程式可由專案任何模組中的程式存取。 Friend 程式不會出現在其父類別的 類型庫 中,也不會晚期綁定 Friend 程式。

所有可執行程式代碼都必須在程式中。 您無法在另一個 Property 、 Sub 或 Function 程式內定義 Property Let 程式。

Exit Property 語 句會立即結束 Property Let 程式。 程序執行會在呼叫 Property Let 程式的 語句後面繼續執行 語句。 任何數目的 Exit Property 語 句都可以出現在 Property Let 程式中的任何位置。

如同 函式 和 屬性取得 程式, Property Let 程式是另一個程式,可以接受自變數、執行一系列的語句,以及變更其自變數的值。 不過,不同於 函式 和 屬性取得 程式,這兩個程式都會傳回值,您只能在屬性指派表達式或 Let 語句的左側使用 Property Let 程式。

這個範例會使用 Property Let 語句來定義將值指派給屬性的程式。 屬性會識別繪圖套件的畫筆色彩。

Dim CurrentColor As Integer 
Const BLACK = 0, RED = 1, GREEN = 2, BLUE = 3 
' Set the pen color property for a Drawing package. 
' The module-level variable CurrentColor is set to 
' a numeric value that identifies the color used for drawing. 
Property Let PenColor(ColorName As String) 
 Select Case ColorName ' Check color name string. 
 Case "Red" 
 CurrentColor = RED ' Assign value for Red. 
 Case "Green" 
 CurrentColor = GREEN ' Assign value for Green. 
 Case "Blue" 
 CurrentColor = BLUE ' Assign value for Blue. 
 Case Else 
 CurrentColor = BLACK ' Assign default value. 
 End Select 
End Property 
' The following code sets the PenColor property for a drawing package 
' by calling the Property let procedure. 
PenColor = "Red" 
              呼叫屬性程式
              設定屬性時執行程序代碼
              撰寫屬性程式

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。