Shiny Language Reference

Language Reference > User Interface


idfromname

int idfromname(string Name);

 

Synonyms:

int ifn(string Name);
 

Returns the control ID associated with the friendly name

The IDFROMNAME statement returns the control ID of the control assigned the specified friendly name. Controls can be assigned friendly names by using the setcontrolname statement, or by right-clicking a control in the Panel Designer, selecting "Set Properties", and entering a name in the appropriate field.

The extremely short synonym of IFN is provided as this statement will be used regularly. There is no difference in using the IFN synonym to the full IDFROMNAME.

 

Parameters

Name

The friendly name to return the ID of.

 

Return Value

The Control ID associated with the name, or -1 if the statement failed (for example, a friendly name that hasn't been associated with a control was provided).

 

Example Code

function Init()
{
    // Create a "dynamic" button at runtime in the normal way
    int ExplorerButtonID = createbutton(1, 10, 10, 50, 20);

    // Associate the friendly name "ExpButton" with the control ID
    setcontrolname(ExplorerButtonID, "ExpButton"):

    // Use the friendly name to set the handler, instead of the control ID
    sethandler(idfromname("ExpButton"), "ExplorerHandler");

    // Exactly the same result, but using the shorthand version
    sethandler(ifn("ExpButton"), "ExplorerHandler");
}