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.
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.
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).
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
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.
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.)
Yeah I also have the feeling that it's something simple we're missing, thank you anyway. Does anyone else have an idea?
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.