ش | ی | د | س | چ | پ | ج |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
ایجاد 5 Label در فرم :
Private click1 As New ClickLabel
Private click2 As New ClickLabel
Private click3 As New ClickLabel
Private click4 As New ClickLabel
Private click5 As New ClickLabel
Private Sub Form_Load()
Set click1.ClickLabel = Me.Label0
Set click2.ClickLabel = Me.Label1
Set click3.ClickLabel = Me.Label2
Set click4.ClickLabel = Me.Label3
Set click5.ClickLabel = Me.Label4
End Sub
کلاس ماژول به نام ClickLabel
Private withEvents mlabel as Access.Label
Public Property Get ClickLabel() As Access.LabelSet ClickLabel = mLabel End Property Public Property Set ClickLabel(ByVal lblClickLabel As Access.Label) Set mLabel = lblClickLabel mLabel.OnClick = "[Event Procedure]" mLabel.OnMouseUp = "[Event Procedure]" End Property Private Sub mLabel_Click() 'run code here MsgBox "You clicked label " & mLabel.Name If mLabel.ForeColor = vbRed Then mLabel.ForeColor = vbGreen Else mLabel.ForeColor = vbRed End If End Sub Private Sub mLabel_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) MsgBox "You moused up from " & mLabel.Name & "It is associated with record" & mRecordID End Sub
عملکردش چییست؟ بعد از ایجاد 5 لیبل در فرم زمانیکه روی لیبل کلیک کنید پیغامی حاوی نام لیبل را به شما نمایش داده و رنگ آن تغییر میکند البته mRecordID در کدهای بالا اعمال نشده که می توان آنرا هم ساخت و برای هر لیبل ID ساخت.
Set click5.ClickLabel = Me.Label4
click5.RecordID = 5
RecordID = mRecordID
you can only use a Property Let procedure on the left side of a property assignment expression or Let statement.
Private mstrPropertyName As StringProperty Get PropertyName() As StringPropertyName = mstrPropertyNameEnd Property' You would use Let because String is a value data typeProperty Let PropertyName(rData As String)mstrPropertyName = rDataEnd Property
IMPORTANT :
The Set statement is used to make a reference of an object to an object variable. You don't have to use the Set keyword, if you are dealing with primitive and native built-in types such as integer, double, string and so on.
The syntax of Property Set is parallel to the Property Let procedure. The only difference is that the argument is an object data type, and the VBA Set keyword is used for the assignment within the body of the Property Set. The following is an example of hypothetical Property Set procedure that accepts a recordset object and assigns it to a private variable named m_ Products:
PROPERTY SET همراستای PROPERTY LET است و تنها فرقی که دارد این است که دیتا تایپ آرگومان OBJECT است.
Public Property Set Products(Value As ADO.Recordset) If Not Value Is Nothing Then Set m_Products = Value End If End Property