RaiseEvent example

Wanting to see an actual example of a coded RaiseEvent statement.

E.g. If one wants the keypress in a TextField1 Control to create an event in say a Default PushButton1, simulating PushButton1 KeyDown event, how does the RaiseEvent statement read in the TextField1.Keypress event ?

I understand the TextField1.Keypress event delivers the ASCII decimal value of the key just entered and
having determined it was the key, RaiseEvent … (what?)

Thank you.

Is your intent to “programmatically” execute the same function that a user might do by click a Pushbutton?
If so, make it easy on yourself…

  • create a method that performs the desired action
  • from the PushButton event… call that method
  • from where ever else in the code you with to “simulate” the event, … call that method

Nothing says that action code for an event (pushbutton or otherwise) needs to be IN the “Action Event”

you have to create your own subclasses to add event definitions to them

  1. subclass textfield by dragging one from the right hand library all the way to the left navigator
    you should end up with a new item in your project (CustomTextField)

  2. right click on CustomTextField and “Add an event handler” - select the KeyDown event from the list

  3. in the Keydown event handler put

           if Key = chr(3) or key = chr(13) then
                 if raiseEvent EnterPressed() then return true
           end if

          return KeyDown(key)
  1. right click on CustomTextField and “Add an Event DEFINITION”
    in the editor that shows (it looks a lot like the method editor) enter
    the NAME - KeyDown
    parameters - key as string
    return type - boolean

  2. right click on CustomTextField and “Add an Event DEFINITION”
    in the editor that shows (it looks a lot like the method editor) enter
    the NAME - EnterPressed
    return type - boolean

Now when you use this new textfield you’ve created on a layout you will have the option to add the “EnterPressed” event

Here’s a project so you can see how this works

1 Like

It does not read at all.
You might have missed in the LR that RaiseEvent can only be used in a class that defines this event. If you want to have a class fire an event in another class like you describe a class interface could be one solution where your Textfield subclass calls a method on your connected PushButton subclass which then can use RaiseEvent.

Just like Dave wrote: Your example sounds rather like you want to push your button when your textfield has a certain content. For that, you would just use PushButton1.Push from within your TextField1.TextChange (or Lostfocus) code. Trying to raise the PushButton.Action event would not work, only a pushbutton subclass can do so. Using PushButton.Push will make it fire its Action event automatically.