
An Address Book Reader
10-39
set(handles.Contact_Name,'string',Addresses(i).Name)
set(handles.Contact_Phone,'string',Addresses(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 Answer
case 'Yes'
Addresses(end+1).Name = Current_Name; % Grow array by 1
Addresses(end).Phone = Current_Phone;
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',Addresses(handles.Index).Name)
set(handles.Contact_Phone,'String',Addresses(handles.Index).Phon
e)
return
end
The Contact Phone Number Callback
The Contact Phone # text box displays the phone number of the entry listed
in the
Contact Name text box. If you type in a new number click one of the
push buttons, the callback opens a question dialog that asks you if you want to
change the existing number or cancel your change.
Like the
Contact Name text box, this callback uses the index pointer
(
handles.Index) to update the new number in the address book and to revert
to the previously displayed number if the user selects
Cancel from the question
Kommentare zu diesen Handbüchern