BBS: Inland Empire Archive
Date: 04-09-92 (14:46)             Number: 50
From: MICHAEL MALLEY               Refer#: NONE
  To: BOB SEWELL                    Recvd: NO  
Subj: Networks                       Conf: (2) Quik_Bas
BS>  Are there any tricks to writing programs that'll run on
BS>networks? I don't want to write one specifically FOR a
BS>network, I just want to avoid the old "permission denied"
BS>errors from  two programs (or two copies of the same
BS>program, in particular) trying to access the same file.

What you will need to do is to check to see whether or not SHARE is
loaded (which is how *most* BASIC programs lock files), if it is, you
need to open the file explicitly as being locked.  If it's being used,
it will fail, and control will go to your error handling routine.

If SHARE isn't present, you can open the files normally.

If you are wanting more than one program to have access to, say a
database file.  You will need to lock individual records.  There are two
ways to do this.  One is called hard locking, in which you use LOCK and
UNLOCK on the file.  The other is soft locking, which typically writes a
flag byte to the record being used, and then erases that flag when it's
done.  You will need to take into account deadly embraces in which two
users are attempting to access each other's record at the same time,
since you shouldn't release a record until you can get another one.  It
can be a little tricky, but once you understand the concepts, it comes
pretty easily.  The code to detect SHARE follows:

DIM Regs AS RegType = &H10 * 256
CALL Interrupt(&H2F, Regs, Regs)
IF (255 <> ( AND 255)) THEN
    PRINT "SHARE must be installed."

If you need more help, leave me a message here or on Strawberry, and we
can meet and go over the code.

- Michael

 * SLMR 2.1a * Help me!  Someone turned reality back on.

--- Maximus 2.01wb
 * Origin: UltraTech - Nashville, TN  (615) 356-0453 {HST} (1:116/30)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET