cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
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

 

 

7 REPLIES 7
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?

DJM
DJM
Level I

Re: Open file and continue script

So basically this...

Open(
Pick File(),
.....
)

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);
DJM
DJM
Level I

Re: Open file and continue script

It's better if you do something like this maybe? See the bold text, and then everything else is just optional, based on what I needed to do with my data.

 

Open(
Pick File(),
Worksheets( "Data" ),
Use for all sheets( 1 ),
Concatenate Worksheets( 0 ),
Create Concatenation Column( 0 ),
Worksheet Settings(
1,
Has Column Headers( 1 ),
Number of Rows in Headers( 4 ),
Headers Start on Row( 21 ),
Data Starts on Row( 25 ),
Data Starts on Column( 1 ),
Data Ends on Row( 0 ),
Data Ends on Column( 0 ),
Replicated Spanned Rows( 1 ),
Replicated Spanned Headers( 0 ),
Suppress Hidden Rows( 1 ),
Suppress Hidden Columns( 1 ),
Suppress Empty Columns( 1 ),
Treat as Hierarchy( 0 ),
Multiple Series Stack( 0 ),
Import Cell Colors( 0 ),
Limit Column Detect( 0 ),
Column Separator String( "-" )
)
)