Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The application package I had working in Mathematica 8 no longer works in Mathematica 9. I believe the problem lies in how I cycle through cells and test for reaching the last cell of the notebook. In MyTools\MySubTools1, I previously used:

SelectionMove[nb, Next, Cell];
  While[(*Keep moving cell by cell until the end of the notebook*)
   MathLink`CallFrontEnd[FrontEnd`CellInformation[FrontEnd`NotebookSelection[nb]]]=!=$Failed,
   (*Code*) 
   SelectionMove[nb, Next, Cell]}];

but have since changed the code to:

SelectionMove[nb, Next, Cell];
  While[(*Keep moving cell by cell until the end of the notebook*)
   Developer`CellInformation[nb] =!= $Failed,
   (*Code*) 
   SelectionMove[nb, Next, Cell]}];

To my package I have added:

BeginPackage["MyTools`", {"Developer`", "MyTools`MySubTools1`", "MyTools`MySubTools2`"}]

The updated code now works as required when debugging in Eclipse but not when running in Mathematica.

What is the best way to check whether I have reached the end of the notebook?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Testing for an empty list works ok, e.g.:-

ClearOutput[] := Module[{thisnotebook, sel},
  thisnotebook = EvaluationNotebook[];
  NotebookFind[thisnotebook, "EditorInterface[\"Start\"]", All];
  sel = Null;
  While[sel =!= {},
   SelectionMove[thisnotebook, Next, Cell];
   sel = NotebookRead[thisnotebook];
   NotebookDelete[thisnotebook]];
  NotebookSave[thisnotebook]]
share|improve this answer
    
Thanks. This method seems more robust (and easier to read) than the other versions. –  MLD Feb 12 '13 at 5:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.