Problems With GUI Running the Program
Show older comments
I am trying to create a GUI program that will calculate a loan payment with interest as well as duration in mounths and I keep getting the following errors well trying to run the program.
Below is the code:
function varargout = project_GUI2(varargin)
% PROJECT_GUI2 MATLAB code for project_GUI2.fig
% PROJECT_GUI2, by itself, creates a new PROJECT_GUI2 or raises the existing
% singleton*.
%
% H = PROJECT_GUI2 returns the handle to a new PROJECT_GUI2 or the handle to
% the existing singleton*.
%
% PROJECT_GUI2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PROJECT_GUI2.M with the given input arguments.
%
% PROJECT_GUI2('Property','Value',...) creates a new PROJECT_GUI2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before project_GUI2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to project_GUI2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help project_GUI2
% Last Modified by GUIDE v2.5 10-Dec-2020 11:14:23
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @project_GUI2_OpeningFcn, ...
'gui_OutputFcn', @project_GUI2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before project_GUI2 is made visible.
function project_GUI2_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to project_GUI2 (see VARARGIN)
% Choose default command line output for project_GUI2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes project_GUI2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = project_GUI2_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function amount_owed_Callback(~, ~, ~)
% hObject handle to amount_owed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of amount_owed as text
% str2double(get(hObject,'String')) returns contents of amount_owed as a double
% --- Executes during object creation, after setting all properties.
function amount_owed_CreateFcn(hObject, ~, ~)
% hObject handle to amount_owed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(~, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function interest_Callback(hObject, eventdata, handles)
% hObject handle to interest (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of interest as text
% str2double(get(hObject,'String')) returns contents of interest as a double
% --- Executes during object creation, after setting all properties.
function interest_CreateFcn(hObject, eventdata, handles)
% hObject handle to interest (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton1
function monthly_payment_Callback(hObject, eventdata, handles)
% hObject handle to monthly_payment (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of monthly_payment as text
% str2double(get(hObject,'String')) returns contents of monthly_payment as a double
% --- Executes during object creation, after setting all properties.
function monthly_payment_CreateFcn(hObject, eventdata, handles)
% hObject handle to monthly_payment (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function total_paid_Callback(hObject, eventdata, handles)
% hObject handle to total_paid (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of total_paid as text
% str2double(get(hObject,'String')) returns contents of total_paid as a double
% --- Executes during object creation, after setting all properties.
function total_paid_CreateFcn(hObject, eventdata, handles)
% hObject handle to total_paid (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in suggested_duration.
function suggested_duration_Callback(hObject, eventdata, handles)
% hObject handle to suggested_duration (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
IP=str2double(get(handles.interest,'string'));
AO=str2double(get(handles.amount_owed,'string'));
IR=IP/100
if AO >= 0 && AO < 10000
T = 120;
elseif AO > 10000 && AO < 25000
T = 126;
elseif AO > 25000 && AO < 50000
T = 144;
elseif AO > 50000 && AO < 80000
T = 180;
elseif AO > 80000 && AO < 150000
T = 240;
end
num2str(set(handles.time,'string',T));
function time_Callback(hObject, eventdata, handles)
% hObject handle to time (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of time as text
% str2double(get(hObject,'String')) returns contents of time as a double
% --- Executes during object creation, after setting all properties.
function time_CreateFcn(hObject, eventdata, handles)
% hObject handle to time (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in RUN.
function RUN_Callback(hObject, eventdata, handles)
% hObject handle to RUN (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
IP=str2double(get(handles.interest,'string'));
AO=str2double(get(handles.amount_owed,'string'));
T= str2double(get(handle.toatal_paid,'string'));
MP = AO * (IR*((1+IR)^T) / ((1+IR)^T-1));
AP = MP*T;
num2str(set(handles.monthly_payment,'string',MP));
num2str(set(handles.total_paid,'string',AP));
Attached is the errors that appear:
project_GUI2
The class handle has no Constant property or Static method named 'toatal_paid'.
Error in project_GUI2>RUN_Callback (line 288)
T= str2double(get(handle.toatal_paid,'string'));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in project_GUI2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)project_GUI2('RUN_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Answers (1)
Image Analyst
on 2 May 2022
0 votes
It's best if you attach the .fig file and the .m file so we can try to run it and open it up in GUIDE, for example to check if the control has a tag of "toatal_paid" or "total_paid". Why would you have a control called "toatal_paid"?
Categories
Find more on Graphics Object Properties 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!