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

Answers (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

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 6 Mar 2012

Community Treasure Hunt

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

Start Hunting!