none
When opening text file for append is it exclusive open RRS feed

  • Question

  • My problem. I need to write a short vbscript to put some info into a text file for tracking changes of dates on customer orders. If I open the text file for append is this exclusive or "if it happens" can 2 users have the file open for append and both lines will be wrote to the file. It is just a simple line of order number, 3 dates, user name and a time stamp. So it should be very quick open , write and close. The possibility of 2 users having it open is very slim BUT, I want to cover the possibility.

    Thanks

    Joel

    Monday, February 27, 2017 6:13 PM

Answers

  • I am not designing a database or application. I am the end user of the application that wants to get some tracking info so when users start pointing fingers at each other saying they didn't do it.

    Writing to a text file to try to keep track of this is exactly the wrong thing to do if this is what you want to accomplish. You need to ask your database for auditing information.

    As I already noted, this is not the right forum to be asking your question in the first place. You need to ask the developer of your application for how to do this properly.


    -- Bill Stewart [Bill_Stewart]

    Monday, February 27, 2017 8:24 PM
    Moderator

All replies

  • It all depends on what you use to open the file and how you set the "shared" options.

    Without a code example the question cannot be answered.

    Note that PowerShell has no CmdLets that can "logically open" a text file.


    \_(ツ)_/

    Monday, February 27, 2017 6:38 PM
  • Sorry about that.

    TextLine = CustOrderNum &","& TimeStamp &","& User Name &","& PromiseShipDate &","& DesiredShipDate &","& ShipDate

    Dim OutFileName

         OutFileName = "C:\CustomerOrders.txt"       This is not the actual file name for now

    Dim Fso

       set fso = Createobject ("Scripting.FileSystemObject")

       Set Outfile = fso.OpenTextFile(OutputFileName,8,true)

       OutFile.Writeline  TextLine

    Outfile.close

    I was in a hurry to get an Idea of how this would work if 2 or 3 people are in the same customer order trying to get things done. We have a customer rep talking to the customer as to when they want the order, Purchasing setting dates as to when they can get parts in to make the order and a scheduler that is trying to figure out when the jobs can be sent to the shop floor to be made. So no one knows who did what when.

    Thank you for your help

    Joel

     

    Monday, February 27, 2017 7:20 PM
  • Until you close the file in VBScript it is open exclusively.

    You should be using a database like Access which has record locking semantics and allows multiple access without errors and without conflicts.  This cannot be done in any reliable way with VBScript text files.

    MSAccess can manage this data and can be fed and built with a simple GUI design tool built into Access..  It can also exchange data easily with other systems in almost any format.


    \_(ツ)_/


    • Edited by jrv Monday, February 27, 2017 7:25 PM
    Monday, February 27, 2017 7:22 PM
  • You can't have more than one person write to a plain-text file at a time. (Which write takes precedence if the writes are simultaneous?) You also have the additional problems that if anyone can write to the file, they can forge data written or corrupt or delete other data in the file as well.

    -- Bill Stewart [Bill_Stewart]

    Monday, February 27, 2017 7:24 PM
    Moderator
  • Unfurtunatly this script is going into our ERP system which can look for and fire off specially named scripts when certain things happen like saving a customer order Macro name of "VMORDENT_OnSave". The users will not know (Unless someone tells them) that this is even happening and the file I can put on the server in a out of the way folder. Just to get this started working I would like to concentrate on the first thing and that is if 2 users write at the same time that it will work with out something getting messed up.

    Thanks

    Joel

    Monday, February 27, 2017 7:41 PM
  • Bill

    Thanks for the reply. Please see reply to jrv.

    Monday, February 27, 2017 7:42 PM
  • Sorry, but this is not a database or application design and consulting forum.

    -- Bill Stewart [Bill_Stewart]

    Monday, February 27, 2017 7:53 PM
    Moderator
  • Unfurtunatly this script is going into our ERP system which can look for and fire off specially named scripts when certain things happen like saving a customer order Macro name of "VMORDENT_OnSave". The users will not know (Unless someone tells them) that this is even happening and the file I can put on the server in a out of the way folder. Just to get this started working I would like to concentrate on the first thing and that is if 2 users write at the same time that it will work with out something getting messed up.

    Thanks

    Joel

    If one user has the file open then the next user will get an error.  You cannot transact writes on a text file with VBScript and if users are trying to write the same record that last user to write wins.

    This is why we have databases.

    We cannot know what you are trying to do or what the rules are from your posts.  I suggest contacting a good programmer to help you sort this out.

    The example you have given will always allow the last user that successfully write to the file to create a new file but the user can also get an error because the file is already open by another user.  Writes by any previous user will be lost.


    \_(ツ)_/

    Monday, February 27, 2017 8:03 PM
  • I am not designing a database or application. I am the end user of the application that wants to get some tracking info so when users start pointing fingers at each other saying they didn't do it. I can go back into the file and search for that order number and say this is who did what to which date at this time and date. I can write my own little macros in our ERP system to do special things like make sure certain fields of the customer order are filled in and correct.

    Thanks

    Joel

    Monday, February 27, 2017 8:04 PM
  • The users will not be writing the same records. I would like it to "append" to the end of the file each and every time a user does a save on a customer order. So that I can track which user changed what date on the customer order and when they did it. A user may go into the customer order 2 or 3 or more times in a week to update these dates.

    Thanks

    Joel

    Monday, February 27, 2017 8:09 PM
  • I am not designing a database or application. I am the end user of the application that wants to get some tracking info so when users start pointing fingers at each other saying they didn't do it. I can go back into the file and search for that order number and say this is who did what to which date at this time and date. I can write my own little macros in our ERP system to do special things like make sure certain fields of the customer order are filled in and correct.

    Thanks

    Joel

    So you are saying that you want to create a log file of all transactions.  If that is what you want then you will need to not use the "create" component of the open call.  You will also have to test for an error to be sure that the file is not already open and retry until successful.

    You are better off writing separate files per user on their local profile.  This will prevent conflicts.

    For any kind of tracing you are committing yourself to an honest, reliable and accurate trace.  If you are not a technician or programmer then this should be designed and tested by someone with good programming skills.  You cannot make accusations based on faulty software auditing tools.  You may even find yourself in legal jeopardy.


    \_(ツ)_/

    Monday, February 27, 2017 8:10 PM
  • The users will not be writing the same records. I would like it to "append" to the end of the file each and every time a user does a save on a customer order. So that I can track which user changed what date on the customer order and when they did it. A user may go into the customer order 2 or 3 or more times in a week to update these dates.

    Thanks

    Joel

    If the application is updating a database then the database system will have a very accurate tracing and auditing.  Contact the vendor to learn how to enable, access and use this facility.  The backend database should be transacted and will guard against false reporting.


    \_(ツ)_/

    Monday, February 27, 2017 8:12 PM
  • I am not designing a database or application. I am the end user of the application that wants to get some tracking info so when users start pointing fingers at each other saying they didn't do it.

    Writing to a text file to try to keep track of this is exactly the wrong thing to do if this is what you want to accomplish. You need to ask your database for auditing information.

    As I already noted, this is not the right forum to be asking your question in the first place. You need to ask the developer of your application for how to do this properly.


    -- Bill Stewart [Bill_Stewart]

    Monday, February 27, 2017 8:24 PM
    Moderator