Specifications
An Address Book Reader
5-37
• If the name exists in the current address book, the corresponding phone
number is displayed.
• If the name does not exist, a question dialog (
questdlg) asks you if you want
to create a new entry or cancel and return to the name previously displayed.
• If you create a new entry, you must save the MAT-file with the
File -> Save
menu.
Storing and Retrieving Data
This callback makes use of the handles structure to access the contents of the
address book and to maintain an index pointer (
handles.Index) that enables
the callback to determine what name was displayed before it was changed by
the user. The index pointer indicates what name is currently displayed. The
address book and index pointer fields are added by the
Check_And_Load
function when the GUI is run.
If the user adds a new entry, the callback adds the new name to the address
book and updates the index pointer to reflect the new value displayed. The
updated address book and index pointer are again saved (
guidata) in the
handles structure.
Contact Name Callback
function Contact_Name_Callback(hObject, eventdata, handles)
% Get the strings in the Contact Name and Phone text box
Current_Name = get(handles.Contact_Name,'string');
Current_Phone = get(handles.Contact_Phone,'string');
% If empty then return
if isempty(Current_Name)
return
end
% Get the current list of addresses from the handles structure
Addresses = handles.Addresses;
% Go through the list of contacts
% Determine if the current name matches an existing name
for i = 1:length(Addresses)
if strcmp(Addresses(i).Name,Current_Name)
set(handles.Contact_Name,'string',Addresses(i).Name)
set(handles.Contact_Phone,'string',Addresses(i).Phone)
handles.Index = i;
guidata(hObject, handles)