I have two edittext boxes. I want to give an error message as soon as user clicks another place rather than these edittext boxes. I receive message
Reference to non-existent field 'eth_xegim'.
In fact, I have several edittext boxes before these two. When I print S
, I can see the fieldnames are printed up to xegim
but not xegim
S.fh = figure('Visible','on','numbertitle','off','Name','GUI',...
'units','pixels','Position',[50 50 1500 750]);
% Panel start
S.ph_arazi = uipanel('Parent',S.fh,'Title','Arazi','TitlePosition','centertop',...
'units','pixels','Position',[1180 364 300 244]);
S.sth_xegim = uicontrol(S.ph_arazi,'Style','text','String','x Eksenine gore egim [%]','HorizontalAlignment','left','Position',[10 68 130 18]);
% xegim edittext
S.eth_xegim = uicontrol(S.ph_arazi,'Style','edit','String','0',...
'HorizontalAlignment','right','BackgroundColor','w',...
'Position',[250 68 40 18],'callback',{@errmsg,S});
S.sth_yegim = uicontrol(S.ph_arazi,'Style','text',...
'String','y Eksenine gore egim [%]','HorizontalAlignment','left',...
'Position',[10 40 130 18]);
% xegim edittext
S.eth_yegim = uicontrol(S.ph_arazi,'Style','edit',...
'String','0','HorizontalAlignment','right',...
'BackgroundColor','w','Position',[250 40 40 18],...
'callback',{@errmsg,S});
% error message
function [] = errmsg(varargin)
S = varargin{3}
xegim = get(S.eth_xegim,'String');
xegim = xegim(ismember(xegim,'.:0123456789'));
yegim = get(S.eth_yegim,'String');
yegim = yegim(ismember(yegim,'.:0123456789'));
if isempty(xegim) || isempty(yegim)
if length(S.fh)==1
S.fh(2) = figure('numbertitle','off','Name','Error',...
'menubar','none','units','pixels',...
'Position',[700 400 200 100]);
S.sth_error = uicontrol(S.fh(2),'Style','text',...
'String','Girdiler sayi olmali!','Min',0,'Max',2,...
'BackgroundColor','r','Position',[10 10 180 80]);
ag = findobj;
nf = max(ag(find(ag==fix(ag))));
if nf == 2
close(S.fh(2))
end
S.fh(2) = [];
end
return;
end