Variables, writing to files and their lifespan in a script

Hi,

I’m a novice at programming so this one goes out to all the gurus.

I have a script that logs the test case numbers in a file (below)

Can i open the file, VFSSResults, for readwrite at the beginning of the first script and leave it open while subsequent scripts write to the file then, close it at the end of the last script?

Also, are global variables accessible from other scripts or are they just valid within the script they are written?

Thanks in advance,
Pete

global VFSSResults
put “~/Documents/VFSSResults.txt” into VFSSResults
open file VFSSResults for readwrite
write “Test case 4830 has passed.” & return & “This is part of the script named CreateAccSysError2” & return to file “~/Documents/VFSSResults.txt” at eof
close file VFSSResults

If you were to run a bunch of scripts by calling them from a single script, then you could use a global variable. Globals are accessible by all the scripts and handlers used in a single execution.

If you want to have your logfile accessible across different script runs during a single Eggplant session ( for example, for all the scripts in your schedules tab ), you’ll need to declare the variable as a universal. Once a universal value has its value assigned, that value is retained until you assign it a new value or you quit Eggplant. However, all you’re able to store in the universal variable is a name for the file – you’re not storing a connection id or a link or anything like that – so you’d need to open the file (presumably for updating [appending]) in each script. The main benefit is that you can define your log file once and then reference it anytime you want.