VBScript Execution Cycle

I have a script which collects information from a web form and writes the inputs into a .txt file and then forwards the .txt file as the body of an email.

I am concerned as to whether multiple users filling in the form may be able to hit the submit button at the exact same time and run the script simultaneously causing a collision where the user writes over the others text file, thus mixing user information.

I was wondering if anyone knows the order of process for vbscript? Will script wait till it completes one cycle before starting another?

Or will the server lock the .txt file while it is being written too? Will this throw an error?

I am trying to understand the underlying sequence before I write additional code to create uniques text file names and deleting them once I know they have been passed on to the mail server.

Open for discussion....

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
It may cause you problems. Presumably the files will have to sit around for a good few seconds while they're written to and you get confirmation from the mail server.

As a general rule: If you think it might cause a problem then its best to code as if it was a problem. In this case unique file names would be a good idea.
Here's a function I use sometimes to create filenames for disposable temporary files on the web server.

Function GetRandomFileName()
      Const Source = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
      Dim intLen
      Dim intChar
      Dim strResult
      intLen = Len(Source)
      Randomize Timer
      strResult = ""
      For intChar = 1 To 8
            strResult = strResult & Mid(Source, Int(Rnd(1) * intLen) + 1, 1)
      GetRandomFileName = strResult
End Function

Instead of hard-coding the filename, make the filename a variable (say, strFileName), and do something like:

    strFileName = <pathwherethefilegoes> & GetRandomFileName & ".txt"

Then after you do the attach to the email, delete that file.  Alternatively, you could let them sit around and have the server run a job overnight to delete all the temporary files that were created that day.

Is it necessary that the data be attached to the email as a file at all?  Why can it not be simply the body of the message itself?  If you can just write the information into a string instead of into a file, then you could use the string's contents as the message body, and avoid the file issue altogether.

Hi rockymagee,

Why not just use the session ID for you file name:
  strFilename = <path> & session.sessionID & ".txt"

The session ID is generated by the server when the user connects to the session and is very simple to access.  You code to Session_OnEnd section of the global.asa file to automatically deal with temp files that don't get deleted properly.

Hope this helps,
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

rockymageeAuthor Commented:
Thanks for the responses .... I am going to implement the unique file fix using the session ID as the file name.  


Can you give me a little more explanation on using the global.asa to deal with the temp files ....


In the global.asa file in the Session_OnEnd section add code similar to the following:
set fs = server.createobject("Scripting.FileSystemObject")
vPath = "c:\web\yourdomain\tempfiles\"   'or where ever you are storing your temp files.
vFile = vPath & session.SessionID
if fs.FileExists(vFile) then
end if
set fs = nothing


Keep in mind that the session does not end when the user leaves your site or closes the browser.  The session ends when it times out, or when session.abandon is called.  So the files will not be removed until one of those two things happens.  The default timeout for a session is 20 minutes.  This can be changed at the server level in IIS Admin or within your scripts using session.timeout = xxx


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rockymageeAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.