User`s guide
An Address Book Reader (GUIDE)
Contact Name Callback
function Contac t_Na me_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(C urre nt_Name)
return
end
% Get the current list of addresses from t he 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(Addre sses (i).Name,Current_Name)
set(handles.Contact_Name,'string',Add resses(i).Name)
set(handles.Contact_Phone,'string',Ad dresses(i).Phone)
handles.Index = i;
guidata(hObject, handles)
return
end
end
% If it's a new name, ask to create a new entry
Answer=questdlg('Do you want to create a new entry?', ...
'Create New Entry', ...
'Yes','Cancel','Yes');
switch Answe r
case 'Yes'
Addresses(end+1).Name = Current_Na me; % Grow array by 1
Addresses(end).Phone = Current_Pho ne;
index = length(Addresses);
handles.Addresses = Addresses;
handles.Index = index;
guidata(hObject, handles)
return
case 'Cancel '
% Revert back to the original number
set(handles.Contact_Name,'String',A ddresses(handles.Index). Name
10-89