# Revision history [back]

### Attach macro to Date Field's Text modified event in basic.

Hello. I want to attach my macro to "Text modified" event of Date Field in Calc spreadsheet. Example code looks like this:

Sub test()
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oForm = oSheet.drawPage.getForms().getByIndex(0)
oDateField = oForm.getByName("DateField1")
' Help me here!
' I need to attach runMe() to "text modified" event of oDateField
End Sub

Sub runMe()
MsgBox "Hurray!"
End Sub


I don't really know where to start with this. I tried reading docs on listeners, but tbh, the whole concept remains very unclear to me.

### Attach macro to Date Field's Text modified event in basic.

Hello. I want to attach my macro to "Text modified" event of Date Field in Calc spreadsheet. Example code looks like this:

Sub test()
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oForm = oSheet.drawPage.getForms().getByIndex(0)
oDateField = oForm.getByName("DateField1")
' Help me here!
' I need to attach runMe() to "text modified" event of oDateField
End Sub

Sub runMe()
MsgBox "Hurray!"
End Sub


I don't really know where to start with this. I tried reading docs on listeners, but tbh, the whole concept remains very unclear to me.

Edit: I've got to the point of something like this:

Sub test()
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oForm = oSheet.drawPage.getForms().getByIndex(0)
oDateField = oForm.getByName("DateField1")
oListener = createUnoListener("Event_", "com.sun.star.beans.XPropertyChangeListener")
End Sub

Sub Event_propertyChange(oEvent)
Mri oEvent
End Sub


And it works fine! :)

Now I just would like to know a way to list/detach listeners from object.

### Attach macro to Date Field's Text modified event in basic.

Hello. I want to attach my macro to "Text modified" event of Date Field in Calc spreadsheet. Example code looks like this:

Sub test()
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oForm = oSheet.drawPage.getForms().getByIndex(0)
oDateField = oForm.getByName("DateField1")
' Help me here!
' I need to attach runMe() to "text modified" event of oDateField
End Sub

Sub runMe()
MsgBox "Hurray!"
End Sub


I don't really know where to start with this. I tried reading docs on listeners, but tbh, the whole concept remains very unclear to me.

Edit: I've got to the point of something like this:

Sub test()
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oForm = oSheet.drawPage.getForms().getByIndex(0)
oDateField = oForm.getByName("DateField1")
oListener = createUnoListener("Event_", "com.sun.star.beans.XPropertyChangeListener")