No announcement yet.

Read-Write problem

  • Filter
  • Time
  • Show
Clear All
new posts

  • Read-Write problem

    this might be a simple question for proffessional programmers, but I can not solve it.

    I wrote two programs in PBCC/4.0. Each program will read and write data to the same .txt file. But I get error messages if one of those programs is writing to the .txt file, during the other program is reading this .txt file.

    How can both programs write and read to the same .txt file at the same time. Priority is that the programs can write to the .txt file. It does not matter if one program can not read data, because the other one is writing. But it should not happen that one or both will crash.



  • #2
    If you are using PB's OPEN statement, open the file from both programs using the SHARED keyword to prevent any access denied errors. | Slam DBMS | PrpT Control | Other Downloads | Contact Me


    • #3
      You need to have opened the files with the correct SHARE and LOCK attributes. (Code not shown).

      But if different programs are reading and writing to the file at the same time, that's really not good enough in itself... you have to code in some file integrity.

      Here's a link to my website you may find useful:

      "Fundamentals Of Multi-User Programming." Article published in December 1995 issue of "BASICally Speaking" magazine discussing the principles of writing multi-user programs; code samples in BASIC. Rich Text format; placed in the Public Domain June 2005

      (Code is PB/DOS, but it's the same for Windows)

      >But it should not happen that one or both will crash.

      If "Crash" here means a protection fault, that's almost certainly caused by not properly handling the ERR value returned by the compiler when OPEN, GET/INPUT/LINE INPUT or PUT/PRINT# fails. (Code not shown).

      Last edited by Michael Mattias; 21 Jan 2008, 10:51 AM.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]