New Radio Buttons

I noticed that when you do a GuiSetCheck for a radio button then it loses its value once you click the chart outside of the radio button area. I am not sure if I use it incorrectly but when I set the GuiCheckBox this is not the case.

i made some example code. When you start the code it should set the first radio button. When you click from 1, to 2 etc it works. However, when you click the chart outside of the radio button area, the trace value returned for all the radio buttons is -1. They lost their value. Am I doing something wrong?

thanks

per1 = Param( "Period 1", 20, 1, 500, 1 );
per2 = Param( "Period 2", 80, 1, 500, 1 );
per3 = Param( "Period 3", 300, 1, 500, 1 );
reset = ParamTrigger( "Reset", "Press Here" );

function calculateSineFunction( per )
{
    ff = sin( 2 * ( 4 * atan( 1 ) ) * Cum( 1 ) / per );
    StaticVarSet( "sinefunc", ff );
}

function getSineFunction()
{
    return StaticVarGet( "sinefunc" );
}


id0 = GuiGetEvent( 0, 0 );
id1 = GuiGetEvent( 0, 1 );

GfxSelectSolidBrush( colorBrightGreen );
x1 = 0;
x2 = 100;
y1 = 30;
y2 = 130;
x3 = 5;
y3 = 5;
GfxRoundRect( x1, y1, x2, y2, x3, y3 );

GuiRadio( "Radio 1", 40, 10, 30, 100, 20, 1 );
GuiRadio( "Radio 2", 41, 10, 50, 100, 20, 1 );
GuiRadio( "Radio 3", 42, 10, 70, 100, 20, 1 );

GuiCheckBox( "Check 1", 50, 10, 110, 100, 20, 1 );

if( Nz( StaticVarGet( "startval" ) ) == 0 OR reset == 1 )
{
    StaticVarSet( "startval", 1 );
    chk = StaticVarGet( "StartCheck" );

    if( chk == 40 )
    {
        GuiSetCheck( 40, 1 );
    }
    else
        if( chk == 41 )
        {
            GuiSetCheck( 41, 1 );
        }
        else
            if( chk == 42 )
            {
                GuiSetCheck( 42, 1 );
            }
            else
            {
                GuiSetCheck( 40, 1 );
            }
}


// radio button toggle
checked = 1;
unchecked = 0;

if( id0 == 40 AND id1 == 1 )
{
    GuiSetCheck( 40, checked );
    GuiSetCheck( 41, unchecked );
    GuiSetCheck( 42, unchecked );
}
if( id0 == 41 AND id1 == 1 )
{
    GuiSetCheck( 40, unchecked );
    GuiSetCheck( 41, checked );
    GuiSetCheck( 42, unchecked );
}
if( id0 == 42 AND id1 == 1 )
{
    GuiSetCheck( 40, unchecked );
    GuiSetCheck( 41, unchecked );
    GuiSetCheck( 42, checked );
}

// execute activated radio button at each refresh
if( GuiGetCheck( 40 ) == 1 )
{
    calculateSineFunction( per1 );
    rsine = getSineFunction();
    StaticVarSet( "StartCheck", 40, 1 );
}
if( GuiGetCheck( 41 ) == 1 )
{
    calculateSineFunction( per2 );
    rsine = getSineFunction();
    StaticVarSet( "StartCheck", 41, 1 );
}
if( GuiGetCheck( 42 ) == 1 )
{
    calculateSineFunction( per3 );
    rsine = getSineFunction();
    StaticVarSet( "StartCheck", 42, 1 );
}

_TRACE( "Radio 40, 41, 42: " + GuiGetCheck( 40 ) + ", " + GuiGetCheck( 41 ) + ", " + GuiGetCheck( 42 ) +" Check 50: " + GuiGetCheck( 50 ) );

GraphXSpace = 5;
SetChartBkColor( colorBlack );
Plot( rsine, "", colorBlue, styleLine, Null, Null, 0, 0, 2 );


1 Like

A post was merged into an existing topic: AmiBroker 6.25.0 BETA released