cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
shampton82
Level VII

Populate a collistbox from the clipboard

I am looking for a way to populate a collistbox from a list of columns in the clipboard.  I tried the getclipboard() command but since the list that is returned isn't a list of columns names this approach fails.

 

For background, I am copying a list of column names out of one datatable (the names are listed in the rows) and using the copied list of column names as the input for an analysis in another datatables analysis.

 

If I just open the analysis platform (NN) and right click on the X input box I can paste in the column names.

 

shampton82_0-1611779440907.png

 

shampton82_1-1611779481043.png

 

I'd like for the terms to show up in the second box:

shampton82_2-1611779531506.png

So I'd copy the column names and run my script and the columns would be able to be selected in the optional box.

 

thanks for any ideas!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Populate a collistbox from the clipboard

Maybe there is an easier way, but I think the variable clip_items in the script below would get you started.  This takes each line in the clipboard and looks for a matching column.  The rest of the script selects those columns in the data table table.  I run this script from a menu as part of an add-in.

 

names default to here(1);

dt = current data table();

//Get list of columns in clipboard
clip_input = Get Clipboard();
clip = clip_input;

clip_items = {};

done = 0;
for( i = 1, done == 0 & i <= 10000, i++,
	show(clip);
	If ( 
		N Items(Regex Match(clip,"[\!\r\!\n]")) == 0
	,
		if( 
			length(clip) > 0
		, 
			Insert Into( clip_items, clip)
		);
		done = 1;
	,
		thisrow = Regex(clip,"(.+?)[\!\r\!\n]","\!\1");
		if( length(thisrow) > 0, Insert Into( clip_items, thisrow) ) ;
		clip = Regex(clip,"\!\n(.*)","\1");
	);
		
);

if( i > 10000, throw("found more than 10000 variables"));

col_names = dt <<  Get Column Names( String );

For( i = 1, i <= N Items( col_names ), i++,
	if( contains( clip_items, col_names[i] ),
		Column( dt, i ) << Set Selected ( 1 );,
		Column( dt, i ) << Set Selected( 0 );,
	)
);

 

View solution in original post

2 REPLIES 2
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Populate a collistbox from the clipboard

Maybe there is an easier way, but I think the variable clip_items in the script below would get you started.  This takes each line in the clipboard and looks for a matching column.  The rest of the script selects those columns in the data table table.  I run this script from a menu as part of an add-in.

 

names default to here(1);

dt = current data table();

//Get list of columns in clipboard
clip_input = Get Clipboard();
clip = clip_input;

clip_items = {};

done = 0;
for( i = 1, done == 0 & i <= 10000, i++,
	show(clip);
	If ( 
		N Items(Regex Match(clip,"[\!\r\!\n]")) == 0
	,
		if( 
			length(clip) > 0
		, 
			Insert Into( clip_items, clip)
		);
		done = 1;
	,
		thisrow = Regex(clip,"(.+?)[\!\r\!\n]","\!\1");
		if( length(thisrow) > 0, Insert Into( clip_items, thisrow) ) ;
		clip = Regex(clip,"\!\n(.*)","\1");
	);
		
);

if( i > 10000, throw("found more than 10000 variables"));

col_names = dt <<  Get Column Names( String );

For( i = 1, i <= N Items( col_names ), i++,
	if( contains( clip_items, col_names[i] ),
		Column( dt, i ) << Set Selected ( 1 );,
		Column( dt, i ) << Set Selected( 0 );,
	)
);

 

shampton82
Level VII

Re: Populate a collistbox from the clipboard

That worked really well!

I added your code to this and I'm good to go:

selCols = dt << Get selected Columns( String );

obj2=new window("Reponse Variable",
			<<Modal,
			<<Return Result,
			LineupBox( NCol( 1 ), Spacing( 5 ),
			choseny = ColListBox( dt, all, <<Set Data Type( "Numeric" ) )
			),
			V List Box(
				chosenx = ColListBox(dt,<<append(eval(selcols))),
			),
			H List Box( Button Box( "OK" ), Button Box( "Cancel" ) )
);