Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 73,381 times

Contents

Related Categories

Files and Folders - Advanced open options

Advanced open options

You might want, at some stage more control over what happens when opening a file. For example, you might want to prevent other applications from writing to it, while you were reading it, or prevent them from reading the file at all! This is all done using different options in the Open statement, and is actually quite simple. To use these, you simply use one of the following keywords after the As Input/Output part of the statement. For example,

Open File For Method LockOptions As nFileNum

The different lock options are explained below:

Shared Lets other applications (and the OS) do what it wants with the file, even if you are modifying it.
Lock Read Prevents other applications from reading the file, until you close it.
Lock Write Prevents other applications from writing to the file, until you close it.
Lock Read Write Prevents other applications from writing to the file or reading it, until you close it.

The last three options also prevent the open file from being deleted, and your program getting a nasty shock when it tries to write to/read from it again!

So,

Open App.Path & "\test.txt" For Input Lock Read Write As nFileNum

opens text.txt for Input, and prevents other applications from reading or writing to it, and stops it from being deleted.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • help

    Posted by tieungao35 on 09 Nov 2005

    Hi all,
    I am a new beginner of Visual basic 6. Even though i read James's article, i don't know how to create a project and add his code as a new module.
    Could you please show me how to create 1...

  • INI files

    Posted by TomDooley on 26 Sep 2005

    Hello,

    the article of James is not state of the art.
    To import win32 functions is not the way how you should work with the .NET framework. With a little bit pation you can write a own managed code...

  • Copying folders including subdirectories

    Posted by kingman29 on 07 Jul 2005

    I am using deppfreeze in my internet cafe.This program protects hard drive from every changes and does not allow save games.When computer restarted all saves dissapear from hard drive.I know the game...

  • ei.

    Posted by po_tph on 20 Mar 2005

    do you a source code of hing folders???

  • hide folder source code???

    Posted by po_tph on 20 Mar 2005

    can anybody plz help me i want to have a sourcec code of hidng folders in windows directory.thanks