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
Edde
Level II

Check if table is read-only?

Hey,

I have a large jsl script in which at one stage it opens a couple of data tables, puts data in them, saves them and closes them.

Now, normally it runs fine without any issues. But the data tables it opens are on the company server and it happens occasionally that someone else has the file open, meaning that the script opens a read-only version, and can't save to it.

Is there any way I can add to the script a way to check if the file is open in read-only mode, so I can cancel the script and warn the user? Something similar to Excel where if you open a file in use by someone else you get a message "File in use by X, do you want to open a read-only version?".

Thanks,
Edvin
1 ACCEPTED SOLUTION

Accepted Solutions
Edde
Level II

Re: Check if table is read-only?

I finally found a solution that works, so I'm posting it in case someone else finds this thread in the future.

 

dt = Data Table("Untitled");

Try(test = LogCapture(dt << save));
If(Contains(test, "problem"),
	New Window("Error",
		<<modal,
		Text Box("The document is read-only")
	);
	Stop();
)

If the table is read-only and can not be locked, test will become

test = "
I/O problem.
File not open in Write mode. 
";

hence why the Contains(test, "problem") works.

View solution in original post

9 REPLIES 9
Edde
Level II

Re: Check if table is read-only?

Just wanted to clarify a bit more, the user does get an error message that says "I/O problem. File not open in write mode."

It only appears when the script tries to save the table, so it can save table 1 and 2, but fail to save table 3, which messes with my data handling.

I want to add something that checks for write mode before trying to save any of the tables. I'm using JMP 13.

Re: Check if table is read-only?

See Help > Scripting Index. Search for "lock" and look up the Get Edit Lock and Set Edit Lock messages. The first one will get the status information that you want. The second one will describe the options that might be returned.

Re: Check if table is read-only?

Forget my suggestion above. The edit locks are separate from the older lock mechanism. A simple approach is to open the data table and send the << Get Lock message to any column. If the data table is locked, then so are all of the columns. The result should be true (1).

Edde
Level II

Re: Check if table is read-only?

Hey, thank you so much for the replies. Unfortunately, neither of the solutions work for me, << Get Lock returns '0' and << Get Edit Lock returns 'Empty()'.

I now have a table open on a different computer, and on my own. I can edit it as much as I want on my own computer, nothing is locked. But when I try to save it, I cannot, and I get the same error message as before, "I/O problem. File not open in write mode.".

Re: Check if table is read-only?

OK, maybe use the Try( expr1, expr2 ) function. The first argument is an expression that is always evaluated. Use your save operation for the first argument. The second argument is an expression that is only evaluated if the first argument generates an error. This way you can trap the error.

 

Names Default to Here( 1 );

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// changes made to data table, save table

Try(
	Close( dt, Save ),
	Print( "Data table locked" );
);

// rest of script
Edde
Level II

Re: Check if table is read-only?

Hey,

I've tried this solution, and tried to construct the Try function in a couple different ways, but it does not seem to ever reach the 2nd expression, even though the first one does generate an error. The table is still closed, but not saved. Here is how the log file looks:

 

Names Default to Here(1);
dt = Data Table("CharData G4 v3.0");

dt << add rows(1);

Try(
	Close( dt, Save ),
	Print( "Data table locked" );
);


I/O problem.
File not open in Write mode. 

Re: Check if table is read-only?

Sorry, I have run out of ideas. Perhaps another contributor can think of a way. (It is probably something simple that has not occurred to me.)

Edde
Level II

Re: Check if table is read-only?

Yeah I also have the feeling that it's something simple we're missing, thank you anyway. Does anyone else have an idea?

Edde
Level II

Re: Check if table is read-only?

I finally found a solution that works, so I'm posting it in case someone else finds this thread in the future.

 

dt = Data Table("Untitled");

Try(test = LogCapture(dt << save));
If(Contains(test, "problem"),
	New Window("Error",
		<<modal,
		Text Box("The document is read-only")
	);
	Stop();
)

If the table is read-only and can not be locked, test will become

test = "
I/O problem.
File not open in Write mode. 
";

hence why the Contains(test, "problem") works.