Caching the archive namesRather than walking through the Newsletters folder and getting a list of filenames every time someone visits the archive, I store the filenames (which are really the dates of the newsletters) in Application variables. (Read more about Application variables)// get data from Application variable
nTotal = Application ( 'TotalNewsletters' ) - 0;
if ( isNaN ( nTotal ) )
{
// no newsletters in Application, so add them
nTotal = 0;
/* WalkFolders( ) goes here */
// add to Application
Application.Lock ( );
Application ( 'TotalNewsletters' ) = nTotal;
for ( var nIssue=0; nIssue<nTotal; nIssue++ )
Application ( 'Newsletter' + nIssue ) = sDates [ nIssue ];
Application.Unlock ( );
}
else
{
// get data from Application (saved earlier)
for ( var nIssue=0; nIssue<nTotal; nIssue++ )
sDates [ nIssue ] = '' + Application ( 'Newsletter' + nIssue );
}
|
The first variable we use is "TotalNewsletters", which of course is one result of the previous WalkFolders( ) call. We can tell if the variable has been set yet by testing it with the built-in function IsNaN (NaN means Not-A-Number). If it's NaN then it's initialized to 0 and WalkFolders( ) called to set it and the sDates array. Next the Application is locked so we can add some new variables. As an example, I create "Newsletter0" - "Newsletter20" if there are 20 newsletters found, and the variables contains the date of the newsletter. The the Application is unlocked. Next time through, "TotalNewsletters" will contain a real number, so the sDates array is filled in from the "Newsletter0" - "Newsletter20" variables, saving all those FileSystemObject calls. Part 4: Displaying the available dates... |