0

I have a .csv file with one line that is constantly being overwritten with the most updated data from some data bus. It looks something like this:

Doors
Closed, Open, Closed, Closed,

And it's being updated (lets say every second) so that as soon as a valve changes it will show in the csv file, like so:

Doors
Closed, Closed, Closed, Closed,

If I have a vbscript that is currently reading the line of information will I receive errors by trying to access said file? Here's pretty much the code I have for this part:

    'Create the file system object
Set fso = CreateObject("Scripting.FileSystemObject")

'Initialize a few items
strSource = "C:\Test.csv"

'Open the source file to read it
Set inputFile = fso.OpenTextFile(strSource,ForReading)

'Skip the first line since it is the heading
strLine = inputFile.ReadLine

'Read the file line by line
Do while not inputFile.AtEndOfStream
    strLine = inputFile.ReadLine

    'Split the line on the comma into an array
    strValues = Split(strLine, ",")

The code works for .csv files that aren't currently in use but I was wondering if this will throw errors (even though i'm simply reading it) if the file I am accessing is constantly being updated.

Thanks

thateurokid23
  • 47
  • 1
  • 2
  • 10
  • 1
    It's hard to say -- it might depend on whether the mechanism that is writing/updating the file is locking it down in any way while it's doing its thing. The code you have now looks safe; you may want to add code to handle errors, and if you don't do it already, close the `inputFile` with `inputFile.Close()` and set it to `Nothing` when you're done with it. – Cᴏʀʏ Jul 17 '13 at 17:07
  • 1
    You might run into race conditions like a simultaneous read and write eg you read "Closed, Closed, Closed, Cl". – Papasmile Jul 17 '13 at 17:26

0 Answers0