Error while evaluating UIControl Callback. Trying to get old code to work
조회 수: 4 (최근 30일)
이전 댓글 표시
Previous colleague wrote the following Matlab code in v2015 and it worked fine. I'm encountering errors with v2023b. I've abbreviated some of the code
%Code Start
fig1=figure(1); set(fig1,'Position',window_pos+window_siz,'MenuBar','None','Name','Text1',...
'NumberTitle','off','Color',bckgr_color);
C.Line2Execute = uicontrol('Parent',fig1,'Style','edit','Units','normalized',...
'Position',[0.05,0,0.85,0.05],'BackgroundColor',bckgr_color);
C.Execute = uicontrol('Parent',fig1,'Style','pushbutton','Units','normalized',...
'HorizontalAlignment','center',...
'String','...', 'Position',[0.9,0,0.05,0.05],...
'callback','str2do=get(C.Line2Execute,''string''); try, eval(str2do); catch, disp(''Error!''); end;');
FC2_Gui %Goes to GUI Code
%FC2_Gui
C.panel(1) = uipanel('Parent',fig1,'Position',[0.05,0.05,0.9,0.9],'Title','Test2','FontWeight','Bold');
% ----- set Pressure -------
if PresManual==1,
set(C.panel(1),'Title','Input Pressure');
C.txt(1) = uicontrol('Parent',C.panel(1),'Style','text','Units','normalized',...
'HorizontalAlignment','left',...
'String','Pressure Hg_mm or PSI', 'Position',[0.05,0.85,0.25,0.1]);
C.Press = uicontrol('Parent',C.panel(1),'Style','edit','Units','normalized',...
'Position',[0.30,0.9,0.15,0.08],'BackgroundColor',bckgr_color);
uicontrol(C.Press);
while isempty(get(C.Press,'String')),
pause(1);
end
Pambient=str2num(get(C.Press,'String'))
if Pambient <500,
Pambient = Pambient*760/14.6959;
end;
set(C.txt(1),'String','Pressure Hg_mm');
set(C.Press,'String',num2str(Pambient) );
T.Pambient = Pambient;
end;
% ----- set Temperature if needed -------
if TempManual==1,
set(C.panel(1),'Title','Input Temperature');
C.txt(2) = uicontrol('Parent',C.panel(1),'Style','text','Units','normalized',...
'HorizontalAlignment','left',...
'String','Temperature, ^oC', 'Position',[0.6,0.85,0.25,0.1]);
C.Temp = uicontrol('Parent',C.panel(1),'Style','edit','Units','normalized',...
'Position',[0.85,0.9,0.11,0.08],'BackgroundColor',bckgr_color);
uicontrol(C.Temp);
while isempty(get(C.Temp,'String')),
pause(1);
end
Tambient=str2num(get(C.Temp,'String'))
end;
% ----- Select type ---------
set(C.panel(1),'Title','Select Type');
varnow = { ,1,2,3,4};
for i=length(varnow):-1:1, varnow{i+1}=varnow{i}; end; varnow{1}='';
C.txt(3) = uicontrol('Parent',C.panel(1),'Style','text','Units','normalized',...
'HorizontalAlignment','left',...
'String','Type', 'Position',[0.05,0.75,0.25,0.1]);
C.Type = uicontrol('Parent',C.panel(1),'Style','popup','Units','normalized',...
'Position',[0.30,0.78,0.15,0.1],'BackgroundColor',bckgr_color,...
'String',varnow,...
'callback','alc=get(C.panel(1),''Children''); for i=1:length(alc), if alc(i)==C.Type, myn=i; end; end; try, delete(alc(1:myn-1)); catch; end; try, delete(C.pan); catch; end; FC2_SetGas');
uicontrol(C.Type);
while get(C.Type,'Value')==1
pause(1);
end
When I make a choice on the "Type" dropdown I get the following
Unable to resolve the name 'C.panel'.
Error using FC2_Gui
Error while evaluating UIControl Callback.
This code worked before. I realize the C.Type Callback is written poorly but I'm trying to get it to work temporarily.
Thanks in advance.
댓글 수: 2
Voss
2023년 11월 1일
Can you upload the complete m-file (and associated fig-file, if created in GUIDE), using the paperclip icon?
채택된 답변
Voss
2023년 11월 1일
The Callback of the C.Type popupmenu is defined as the following character vector:
'alc=get(C.panel(1),''Children''); for i=1:length(alc), if alc(i)==C.Type, myn=i; end; end; try, delete(alc(1:myn-1)); catch; end; try, delete(C.pan); catch; end; FC2_SetGas'
character vector callbacks execute in the base workspace, not in the workspace of FC2 (which FC2_Gui shares since FC2_Gui.m is a script), and evidently you don't have a variable called C in your base workspace, so that's why the global variable C is unrecognized.
There are at least a couple of ways to fix this:
- (Recommmended) Change that character vector callback into a function. I've taken this approach in the m-files attached.
or:
- Add the command "global C;" to the beginning of the existing character vector callback.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!