Update active control from method

Hi.
I have written a few lines of code that adds today’s date to a textbox whel ctrl+d is pressed.

[code] dim i as Integer
i = asc(key)

if asc(key) = 4 then
dim j as new date
me.Text = me.text + " " + j.ShortDate
end if
[/code]

Obviously, i don’t want to put this code in the keydown event for every single textbox that requires it.
I tried putting this code in a method but it doesnt let me use (me.text) from inside the method.

How do i get the method to add todays date to the active textbox?

why not simply subclass the textbox?

Never used a subclass before. Don’t know why because that was too easy.
Still have much to learn about Xojo :slight_smile:
Thanks for that

Add a new container class to your project and give it a new name like TextBoxDate. Set the SuperClass to TextField. Add a KeyDown event and enter this code:

if key.Asc = 4 then
dim MyDate as new Date
me.Text = MyDate.ShortDate
end if

Now you can drag the TextBoxDate to any Window or Container in your project. You can also update your normal TextBox controls by selecting each control and set the SuperClass to TextBoxDate.