GuiGetEvent
- get GUI event

GUI functions
(AmiBroker 6.30)


SYNTAX GuiGetEvent( num, what = 0 )
RETURNS NUMBER or STRING
FUNCTION The function retrieves queued GUI event (such as click, edit change, focus change, etc) that was triggered by on-chart GUI control

Parameters:

  • num parameter defines the index of notification in the queue. 0 is first received (or "oldest") since last execution.
  • what, defines what value is returned by GuiGetEvent function:
    • what = 0 - ID of control that received event (number)
    • what = 1 - the notification code (number)
    • what = 2 - the ID, the code and the notification description as text (string)

Usually there is zero (when formula execution was not triggered by UI event) or one event in the queue but note that there can be more than one event notification in the queue if your formula is slow to process. To retrieve them all use increasing "num" parameter as long as GuiGetEvent does not return zero (in what =0, =1 mode) or empty string (what=2).

For more information about using GUI controls see Tutorial: Using on-chart GUI controls

EXAMPLE // EXAMPLE 1. Just read all pending events
for( i = 0; id = GuiGetEvent( i ); i++ )
{
    code = GuiGetEvent( i, 1 );
    text = GuiGetEvent( i, 2 );
}

It is good practice to have a separate function that handles the events as shown below:

// EXAMPLE 2. Read and handle events using switch statement
idMyFirstButton = 1;
idMySecondButton = 2;

function CreateGUI()
{
     GuiButton( "enable", idMyFirstButton, 10, 60, 100, 30, notifyClicked );
     GuiButton( "disable", idMySecondButton, 110, 60, 100, 30, notifyClicked );
}

function HandleEvents()
{
    for ( n = 0; id = GuiGetEvent( n, 0 ); n++ ) // get the id of the event
    {
         code = GuiGetEvent( n, 1 );

         switch ( id )
         {
             case idMyFirstButton:
             // do something
                break;

             case idMySecondButton:
             // do something else
                break;

             default:
                 break;
         }
     }
}

CreateGUI();

HandleEvents();
SEE ALSO GuiButton() function , GuiCheckBox() function , GuiDateTime() function , GuiEdit() function , GuiRadio() function , GuiSlider() function , GuiToggle() function

References:

The GuiGetEvent function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.