Subscribe Bookmark RSS Feed

Display selected file in button box

matt7109

Contributor

Joined:

Jun 9, 2017

Hi there,

I have a button that prompts user to select 2 files. However, once the user clicks the button and picks a file, I would like the path name to show up on the button so that the user knows the file was correctly selected. In the photo below, once a user picks a file, I want that selected path to show up in the highlighted area. 

Button.PNG

Current Code:

New Window( "Data and Limits file",
	<<modal,
	Text box(""),
	Text box("Choose a data file:"),
	Button Box( "Pick file", D = Pick File()),
	//Text box(L),
	Text box (""),
	Text box (""),
	Text box("Choose a limits file:"),
	Button Box( "Pick File", L = Pick File()),
	//Text box(D),
	Text box(""),
	Text box (""),
	);

Thanks!

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is the script.  The documentation on all of the features that can be used with a given function or display object is available at:

     Help==>Scripting Index

It will give you all of the details, and examples 

Names Default To Here( 1 );
New Window( "Data and Limits file",
	<<modal,
	Spacer Box( size( 10, 10 ) ),
	Text Box( "Choose a data file:" ),
	BB1 = Button Box( "Pick file",
		D = Pick File();
		If( D != "",
			BB1 << set button name( D )
		);
	), 
	//Text box(L),
	Spacer Box( size( 20, 10 ) ),
	Text Box( "Choose a limits file:" ),
	BB2 = Button Box( "Pick File",
		L = Pick File();
		If( L != "",
			BB2 << set button name( L )
		);
	), 
	//Text box(D),
	Spacer Box( size( 20, 10 ) ) 

);
Jim
Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

Solution

@txnelson's solution changes the text of the button, which is what the title of your post says you wanted.

 

But, the picture you provided looks like you want the name of the file below the button – not in the button.

 

If that's what you really want here's a modification of Jim's code that will get you there.

 

Names Default To Here( 1 );
New Window( "Data and Limits file",
	<<modal,
	Spacer Box( size( 10, 10 ) ),
	Text Box( "Choose a data file:" ),
	BB1 = Button Box( "Pick file",
		D = Pick File();
		If( D != "",
			file1 << set text( D )
		);
	),
	file1 = Text Box( ), 
	//Text box(L),
	Spacer Box( size( 20, 10 ) );,
	Text Box( "Choose a limits file:" ),
	BB2 = Button Box( "Pick File",
		L = Pick File();
		If( L != "",
			file2 << set text( L )
		);
	),
	file2 = Text Box(  ), 
	//Text box(D),
	Spacer Box( size( 20, 10 ) ) 

	;
);
-Jeff
3 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is the script.  The documentation on all of the features that can be used with a given function or display object is available at:

     Help==>Scripting Index

It will give you all of the details, and examples 

Names Default To Here( 1 );
New Window( "Data and Limits file",
	<<modal,
	Spacer Box( size( 10, 10 ) ),
	Text Box( "Choose a data file:" ),
	BB1 = Button Box( "Pick file",
		D = Pick File();
		If( D != "",
			BB1 << set button name( D )
		);
	), 
	//Text box(L),
	Spacer Box( size( 20, 10 ) ),
	Text Box( "Choose a limits file:" ),
	BB2 = Button Box( "Pick File",
		L = Pick File();
		If( L != "",
			BB2 << set button name( L )
		);
	), 
	//Text box(D),
	Spacer Box( size( 20, 10 ) ) 

);
Jim
matt7109

Contributor

Joined:

Jun 9, 2017

Perfect!!! Thanks so much!

Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

Solution

@txnelson's solution changes the text of the button, which is what the title of your post says you wanted.

 

But, the picture you provided looks like you want the name of the file below the button – not in the button.

 

If that's what you really want here's a modification of Jim's code that will get you there.

 

Names Default To Here( 1 );
New Window( "Data and Limits file",
	<<modal,
	Spacer Box( size( 10, 10 ) ),
	Text Box( "Choose a data file:" ),
	BB1 = Button Box( "Pick file",
		D = Pick File();
		If( D != "",
			file1 << set text( D )
		);
	),
	file1 = Text Box( ), 
	//Text box(L),
	Spacer Box( size( 20, 10 ) );,
	Text Box( "Choose a limits file:" ),
	BB2 = Button Box( "Pick File",
		L = Pick File();
		If( L != "",
			file2 << set text( L )
		);
	),
	file2 = Text Box(  ), 
	//Text box(D),
	Spacer Box( size( 20, 10 ) ) 

	;
);
-Jeff