2
$\begingroup$

I am calling one notebook (N2) from inside another notebook (N1). The results are transferred correctly from the second notebook to the first one. But when I try to compare the results from the two notebooks all symbols calculate in the first Notebook are empty so that I can not use them. For example, first, the value of the "P103mmp" symbol is calculated in Notebook1 correctly. Then, the second Notebook is called using the following script which imports the symbols and associated values from the second notebook correctly.

SetDirectory["D:\\Mehdi"];
nb = NotebookOpen[FileNameJoin[{Directory[], "9.33mmMal.nb"}]];
NotebookEvaluate[nb];

However, later when I want to compare the values of P103mmp with P109mmp in Notebook 1, the P103mmp symbol is empty. Why am I losing the value of P103mmp and how can I fix the issue? Any help is really appreciated.

N.1

Clear["Global`*"];
.
.
.
P103mmp
.
.
.
SetDirectory["D:\\Mehdi"];
nb = NotebookOpen[FileNameJoin[{Directory[], "9.33mmMal.nb"}]];
NotebookEvaluate[nb];
Print["P109mmp=" <> ToString@P109mmp]; (*--Impoerted form N.2--*)
.
.
. 
ValueQ[P103mmp]
False
ValueQ[P109mmp]
True
$\endgroup$
  • 2
    $\begingroup$ Does your 9.33mmMal.nb file also begin with the line Clear["Global`*"];? $\endgroup$ – Natas Jul 20 at 11:12
  • $\begingroup$ Yes! It also starts with Clear ["Global '*"]. $\endgroup$ – Mehdi Ebadi Jul 20 at 14:22
  • 1
    $\begingroup$ Well then that is your answer. Clear["Global`*"]; clears all the variables that have been defined before (in the global context). Remove that line and the variables from notebook 1 remain defined even after loading notebook 2 inside of notebook 1. $\endgroup$ – Natas Jul 20 at 14:37
  • $\begingroup$ Thank you Natas! So, I will remove the ["Global '*"] from Notebook 2 and leave it for Notebook 1 intact. $\endgroup$ – Mehdi Ebadi Jul 20 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.