4
$\begingroup$

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?

$\endgroup$

1 Answer 1

2
$\begingroup$

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]]
$\endgroup$
1
  • $\begingroup$ Thanks. This method seems more robust (and easier to read) than the other versions. $\endgroup$
    – MLD
    Feb 12, 2013 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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