Edit box - Want an error message when a negative value is entered (Beginner)

Can anyone explain to me why this is not working for me. There are no error messages - it just doesn't give me any error box.
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
strng=get(gcbo,'string');
if ~isempty(strng)
val=str2num(strng);
if val < 0
errordlg('Value cannot be negative','Error','modal');
set(gcbo,'string','Try again');
end
end

Respuestas (1)

This worked
function edit2_Callback(hObject, eventdata, handles)
strng=get(gcbo,'string');
val=str2num(strng);
if val < 0
errordlg('Value cannot be negative','Error','modal');
set(gcbo,'string','Try again');
end

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 6 de Mzo. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by