Specifications
An Address Book Reader
5-49
button Callback string includes 'Next' as the last argument. The value of str
is used in
case statements to implement each button’s functionality (see the
code listing below).
Paging Forward or Backward
Prev_Next_Callback gets the current index pointer and the addresses from the
handles structure and, depending on which button the user presses, the index
pointer is decremented or incremented and the corresponding address and
phone number are displayed. The final step stores the new value for the index
pointer in the
handles structure and saves the updated structure using
guidata.
Code Listing
function varargout = Prev_Next_Callback(h,eventdata,handles,str)
% Get the index pointer and the addresses
index = handles.Index;
Addresses = handles.Addresses;
% Depending on whether Prev or Next was clicked change the display
switch str
case 'Prev'
% Decrease the index by one
i = index - 1;
% If the index is less then one then set it equal to the index of the
% last element in the Addresses array
if i < 1
i = length(Addresses);
end
case 'Next'
% Increase the index by one
i = index + 1;
% If the index is greater than the size of the array then point
% to the first item in the Addresses array
if i > length(Addresses)
i = 1;
end
end
% Get the appropriate data for the index in selected
Current_Name = Addresses(i).Name;
Current_Phone = Addresses(i).Phone;