GUI edit text and msgbox problem .. what do I miss

2 views (last 30 days)
Hello,
yesterday I programed partial code that does check values in edit text field for NUMBER and then If that is a number pops out msgbox where that number is shown othervise it htere is STR it pops msg box ERROR.
Unfortunately! It worked well till now. I'm not aware of changing anything! And I cannot find problem.
function koefm_Callback(hObject, eventdata, handles)
input = get(handles.koefm,'String'); %get the input from the edit text field
input = str2num(input); %change from string to number
if isempty(input)
msgboxText{1} = 'BLAH BLAH';
msgbox(msgboxText,'BLAH', 'error');
set(handles.koefm,'String','2') % sets default value
else
input = num2str(input);
msgboxText{1} = 'blah blas';
msgboxText{2} = strcat('blah blah',{' '},input) ;
msgbox(msgboxText,'INFO');
end
It should be in conversion but I can't see the problem.. help please :P
BTW this is command line error msg input =
6
input =
6
??? Undefined function or method 'eq' for input arguments of type 'cell'.
Error in ==> textwrap at 99
Loc=find(Para==ReturnChar);
Error in ==> msgbox at 283
[WrapString,NewMsgTxtPos]=textwrap(MsgHandle,BodyTextString,75);
Error in ==> GUI>koefm_Callback at 95
msgbox(msgboxText,'INFO');
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)GUI('koefm_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

Accepted Answer

Matt Fig
Matt Fig on 12 Jun 2011
This works:
input = get(handles.koefm,'String'); %get the input from the edit text field
% No need to convert to number...
if isempty(input)
msgboxText{1} = 'BLAH BLAH';
msgbox(msgboxText,'BLAH', 'error');
set(handles.koefm,'String','2') % sets default value
else
msgboxText{1} = 'blah blas';
msgboxText{2} = ['blah blah',' ',input]; % The error was here.
msgbox(msgboxText,'INFO');
end
The error was that you were using STRCAT to make a cell array with a sub-cell... Look at the results of what you did:
msgboxText{1} = 'blah blas';
msgboxText{2} = strcat('blah blah',{' '},'45')
msgboxText =
'blah blas' {1x1 cell}
  1 Comment
Lex
Lex on 12 Jun 2011
Thank you mr. Fig :) It worked well even althrough that first conversion was needed. Because It secures field from String valuse.
So I've splitted field to two inputs ;p Input1 is converted to strink and tested for emptyness and after Else statement there is one more input2 where was conv. problem.
THANKS once again! (I'm new a guy to GUI :P )

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion 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!