How to display an error message in GUI?
    9 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
I have a figure of table. The user will insert a data into the table. If the user suddenly inserts the wrong data, the table will be 'NaN'. My question is how I want to make the table does not display 'NaN' on the table but I want an error message appear. I have this coding:
function Mytable1_CreateFcn(hObject, eventdata, handles)
if isnan(Mytable1)
  set(hObject, 'Data', 0);
  errordlg('Input must be a number','Error');
end
handles.Mytable2 = hObject;
guidata(hObject,handles);
But there is an error with this code. Is this coding are correct to answer my question?
0 Commenti
Risposta accettata
  Walter Roberson
      
      
 il 17 Feb 2011
        You wouldn't put the test in the create function, you would put the test in the edit function.
You may also want to uiwait() around the errordlg() so that you force the user to acknowledge the error. Your present code pops up the error but the user can hide it and continue on their way.
3 Commenti
  Walter Roberson
      
      
 il 17 Feb 2011
				ed = errordlg('Input must be a number','Error');
set(ed, 'WindowStyle', 'modal');
uiwait(ed);
It might be possible to make it impossible for the user to hide it, but it probably isn't worth the bother: with the above code, the user will not be able to proceed with anything else.
  Paulo Silva
      
 il 17 Feb 2011
				To show errors I often prefer to have them inside a text box, it's also good to show warnings and important info, also changing the text colors with the message type is great.
Più risposte (2)
Vedere anche
Categorie
				Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



