Specifications
5 GUI Applications
5-34
elseif (length(varargin) == 2 & strcmpi(varargin{1},'book') & (2 ==
exist(varargin{2},'file')))
Check_And_Load(varargin{2},handles);
else
errordlg('File Not Found','File Load Error')
set(handles.Contact_Name,'String','')
set(handles.Contact_Phone,'String','')
end
Loading an Address Book Into the Reader
There are two ways in which an address book (i.e., a MAT-file) is loaded into
the GUI:
• When running the GUI, you can specify a MAT-file as an argument. If you
do not specify an argument, the GUI loads the default address book
(
addrbook.mat).
• The user can select
Open under the File menu to browse for other MAT-files.
Validating the MAT-file
To be a valid address book, the MAT-file must contain a structure called
Addresses that has two fields called Name and Phone. The Check_And_Load
subfunction validates and loads the data with the following steps:
• Loads (
load) the specified file or the default if none is specified.
• Determines if the MAT-file is a valid address book.
• Displays the data if it is valid. If it is not valid, displays an error dialog
(
errordlg).
• Returns
1 for valid MAT-files and 0 if invalid (used by the Open menu
callback)
• Saves the following items in the
handles structure:
- The name of the MAT-file
- The
Addresses structure
- An index pointer indicating which name and phone number are currently
displayed