Borrar filtros
Borrar filtros

Get gui to run a command when getting an error from trying to rewrite a file that is open, or the user cancel during save.

2 visualizaciones (últimos 30 días)
Hi
I have this GUI where the user gets to save a print of the GUI to a PDF, during that process some of the popup-menu, edit-boxes and check-boxes are changed to invisible due to the fact I don't want the "client" to see the input. And after the user has saved the file, the code makes them visible again. But this leaves me with a little problem.
Because if the user tries to overwrite a PDF that is already open, this leaves an error, and the code behind the save function doesn't run, and thereby it doesn't make the popup-menu visible again.
The same occurs of the user cancels the save during the process, here again the different, popup-menu's, edit-boxes and check-boxes are left invisible.
My question is:
Is there a way to catch the error, show it to the user so they know that they are trying to rewrite a file that is open, and then afterwards run the rest of the code so the popup-menu's, edit-boxes and check-boxes becomes visible again?
[FileName,PathName] = uiputfile('*.pdf','Save Print',[handles.workingPath '\Mydata');
I've tried reading try and catch commands, but don't understand what to do.

Respuesta aceptada

Jan
Jan el 19 de En. de 2018
Editada: Jan el 19 de En. de 2018
... Your code to make the GUI parts invisible comes here
Folder = fullfile(handles.workingPath, 'Mydata'); % FULLFILE is safer than []
[FileName, PathName] = uiputfile('*.pdf', 'Save Print', Folder);
if ~isequal(FileName, 0) % User did not hit Cancel
try
... Your code to save the file as PDF
catch ME
% Inform the user about the problem:
fprintf('PDF export failed: %s\n', ME.message);
end
end
... the code to re-enable the visibility again comes here

Más respuestas (0)

Categorías

Más información sobre Dialog Boxes en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by