Using previous edit text value

3 views (last 30 days)
Paul
Paul on 7 Jun 2013
I have created an edit text box that accepts only numeric values, however, when an erroneous value is submitted (i.e. a non numeric value) I would like the program to run with the last numeric value used. For instance, if someone inserted 5, then inserted "pig" I would like the program to continue running with the value 5. Here is my code:
[m_temp,m_stat]=str2num((get(handles.edit5,'string')));
if m_temp ~= round(m_temp)
m_out=round(m_temp);
uiwait(msgbox('Please insert an integer from 0-16 in the Horizontal Lines box','Error'));
elseif m_stat==0
uiwait(msgbox('Please insert an integer from 0-16 in the Horizontal Lines box','Error'));
else m_out=m_temp;
if m_out>16
set(handles.edit5,'string','16');
uiwait(msgbox('Horizontal Lines must be integers from 0-16','Error'));
m_out = 16;
elseif m_out<0
set(handles.edit5,'string','0');
uiwait(msgbox('Horizontal Lines must be integers from 0-16','Error'));
m_out=0;
end;
end;
m=m_out

Accepted Answer

Image Analyst
Image Analyst on 7 Jun 2013
Where is this code? Inside some callback? You will have to validate the number, and if it's valid, save it into a "global" variable (some variable that you can access - see the FAQ), such as a structure called UserSettings or whatever you want to call it. Then the next time a number needs to be validated, if it's not valid, display an error message if you want to, but don't update your validated global variable.
  1 Comment
Paul
Paul on 7 Jun 2013
Making a global variable did it. Thanks for helping a newbie.

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!