# How can I access variables from one .nb file to another .nb file? [closed]

upto last weekend,I wrote my entire Application code in one .nb file.Because of this,it's very difficult for finding the specific code after some time,so

I divided single .nb file to different categories like,one .nb have only designing part,second .nb have only evaluation part and third .nb file have only Variable Initialization.

I divided like this.

initialization file

testing = Style["This is Tested by Infratab Pvt Ltd", Bold, 20, Red]


design.nb file

values = NotebookEvaluate[FileNameJoin[{NotebookDirectory[],"initialization.nb"}]];
button = Button["Ok", MessageDialog[values]]


evalution.nb file

  DynamicModule[
{testCase1 = Null},
(

testCase1  NotebookEvaluate[FileNameJoin[{NotebookDirectory[],"design.nb"}]];
testCase1
),Initialization :> (NotebookEvaluate[FileNameJoin[{NotebookDirectory[],"design.nb"}]]
]


manually,If you can evaluate evalution.nb,it's working fine but after deploying into CDF file it's not working...

I tried with Initialization,Getfunction,still not get it..

can anyone help me?

Note:

I don't want to save that notebooks into Autoload folder,because If you can write code like that, every time user paste that files into his Autoload folder, it's very bad

-
I think you have some errors regarding evalution.nb perhaps testCase1=NotebookEvaluate[...? Anyway, try Manipulate with SaveDefinitions->True. My next advice is to write the code in separate .m files instead of notebooks and perhaps write a proper package. – Ajasja Feb 11 at 10:21
@Ajasja I will try with Manipulate.. – subbu Feb 11 at 10:28
@Ajasja I am also maintain code with in .m file,which code was repeated.But this variable initialization,design,evaluation was not repeated so packages are not needed.. – subbu Feb 11 at 10:45
You have your development all messed up. You really need to do a little bit of software engineering. You should think in terms of modules and packages, not notebooks or files or folders. Forget about notebooks. organize your software in packages and Modules (functions). It does not matter what notebook they are in, that is not important. A notebook is just a file. It has nothing to do with software architecture. – Nasser Feb 11 at 10:51
By default, entities defined (with their definitions evaluated) in one notebook are available to all other notebooks at the same Mathematica session. This is different from the behavior of some other CAS software, hence can be a surprise to newbies. – murray Feb 11 at 17:15
show 1 more comment

## closed as too localized by Yves Klett, Ajasja, Sjoerd C. de Vries, m_goldberg, Oleksandr R.Feb 13 at 4:50

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

## 1 Answer

Try Manipulate with SaveDefinitions->True. My next advice is to write the code in separate .m files instead of notebooks and perhaps write a proper package.

When I started writing larger Mathematica programs I used to have my code first in .nb files. This quickly became unwieldy. Having just .m was better, but now I am sorry I have not started writing proper packages before. Using the Wolfram Workbench helps as well.

-
 Posted as per @Szabolcs new ruthless policy meta.mathematica.stackexchange.com/questions/916/…. (I'm just teasing) – Ajasja Feb 12 at 10:23