cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
JulieSAppel
Level IV

Open file and continue script

Hi,

In a script I´m prompting a user to open a file:

LBSelect = Open( "file path", 
	Use Labels For Var Names( 1 )
	);

This opens a folder and the user has to pick the correct file. When the file has been opened the script should continue with a series of actions based on that file.

How can I make the script wait until a file has been opened? I thought about wait() but that will just state how many seconds it has to wait and as these files tend to be very big this is not a good fit. 

How can I make it wait for the file to open?

Can a modal window be used in any way?

 

Br Julie

 

 

5 REPLIES 5
tom_abramov
Level V

Re: Open file and continue script

Hi,

I have a couple of ideas.

1. try to use wait() with no number inside. It will wait until all previous commands are complete (I hope it is true)

2. make a loop with wait and try

 

For( i = 1, i <= 100, i++, 
	Try(
		LBSelect << Bring Window to front();//run any command on table which will fail in case the table is not ready
		Break();//if not failed - terminate the loop
	,
		Wait( 1 )
	);//if failed - wait 1 second and try again

);

 

Re: Open file and continue script

You are confused. The Open() function opens a file. The Pick File() function presents a dialog and returns a full path to the selected file or missing. So you should call the Pick File() function and use the result to open the file with the Open() function, or call the Open() function without a path.

JulieSAppel
Level IV

Re: Open file and continue script

Ok - I can see that.

Normally I do that when I prompt for a user to open a file (where they navigate to the file themselves). In this case I wanted to add the file path in there to reduce the amount of clicks and then I managed to confuse myself.

Now I´ve done this:

path = Pick File("Select lb", "file path");

LBSelect = Open( path, 
	Use Labels For Var Names( 1 )
	);

But it doesn´t seem to work. The lb file is opened as lb, not as LBSelect.

What am I doing wrong?

David_Burnham
Super User (Alumni)

Re: Open file and continue script

Wait(0)

... is a common method of waiting until a task is completed.  Not sure I've ever had to use it in the context of opening files.  

-Dave
singaraveluR
Level II

Re: Open file and continue script

Are you looking something like this?

 

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( ), 

);

data_file = Open (D);