Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
Level III

## Trouble Closing Button Box window after button was already pressed

My launchWin window consist of interactive button boxes. However when I press the button, the window will not close. Im not sure why. I thought the button is supposed to close automatically after being clicked on

I have the below Code:

//Set the working table as the current table, pay attention to which table is at the top
dt = currentdatatable();

//Create a summary of the total aliquots in each box by BOX ID
sumdt = dt << Summary(
Group( :BOX ID ),
Sum( :Name( "# of aliquots" ) ),
Freq( "None" ),
Weight( "None" )
);
//Calculate Free Space in each box and assign to new col
col5 = sumdt << New Column("FreeSpace", Data Type (Numeric),
Formula(
96 - :Name("Sum(# of aliquots)")

)
);
//sort new table by new col
sumdt << Sort(By(:FreeSpace), Order(Descending), Replace Table);

box10 = sumdt[index(1,10), 1];
row10 = sumdt[index(1,10), 4];
close(sumdt, nosave);

launchWin = New Window( "Launcher",
<<Modal,
V List Box(

Lineup Box( N Col( 4 ), Spacing( 20 ),

Button Box( "Check Space",
New Window ("Available Spaces",
Table Box(
Number Col Box("Box ID", box10),
Number Col Box("Available Slot", row10)
)
)

),

//Cancel
Button Box( "Cancel", Throw( 1 ) )
),
)
);

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Staff

## Re: Trouble Closing Button Box window after button was already pressed

If the Button Box were named "OK", it would close automatically. But you've created your own button with its own name, which is perfectly fine, but the custom button will only do what you tell it to do.

There's two ways to add the ability to close a button's window. One is to assign the Button Box to a variable, and then send it the Close Window message within the button's script:

``````b=Button Box( "Check Space",
New Window( "Available Spaces",
Table Box( Number Col Box( "Box ID", box10 ), Number Col Box( "Available Slot", row10 ) )
);
b<<Close Window;
)
``````

Or you can assign a function to the button and avoid adding a variable to the global namespace:

``````Button Box( "Check Space",
<<Set Function( Function( {this},
New Window( "Available Spaces",
Table Box( Number Col Box( "Box ID", box10 ), Number Col Box( "Available Slot", row10 ) )
);
this<<Close Window
))
)
``````

HTH,

Melanie

2 REPLIES 2
Highlighted
Staff

## Re: Trouble Closing Button Box window after button was already pressed

If the Button Box were named "OK", it would close automatically. But you've created your own button with its own name, which is perfectly fine, but the custom button will only do what you tell it to do.

There's two ways to add the ability to close a button's window. One is to assign the Button Box to a variable, and then send it the Close Window message within the button's script:

``````b=Button Box( "Check Space",
New Window( "Available Spaces",
Table Box( Number Col Box( "Box ID", box10 ), Number Col Box( "Available Slot", row10 ) )
);
b<<Close Window;
)
``````

Or you can assign a function to the button and avoid adding a variable to the global namespace:

``````Button Box( "Check Space",
<<Set Function( Function( {this},
New Window( "Available Spaces",
Table Box( Number Col Box( "Box ID", box10 ), Number Col Box( "Available Slot", row10 ) )
);
this<<Close Window
))
)
``````

HTH,

Melanie

Highlighted
Level III

## Re: Trouble Closing Button Box window after button was already pressed

Thank you!
Article Labels

There are no labels assigned to this post.