Announcement

Collapse
No announcement yet.

Read-Write problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Read-Write problem

    Hello,
    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.

    Thanks!

    Martin

  • #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.
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #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
      http://www.talsystems.com/tsihome_ht...rogramming.rtf

      (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).

      MCM
      Last edited by Michael Mattias; 21 Jan 2008, 09:51 AM.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment

      Working...
      X