Solved

Locking a file

Posted on 1998-06-23
7
154 Views
Last Modified: 2011-09-20
I am using VB4.0 32-bits, and I wish to know how can I lock certain files from other user using it if
one user is already using it.

Something like microsoft word, where if I am already using docA.doc, and user B from another computer can only view this docA.doc but cannot modify it. However, I perfer that user B cannot even view it at all, if the file is being used.

Is there a way I can code it?
0
Comment
Question by:wsm
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:raygibbins
ID: 1464023
In your code you could create a file called docA.loc when a user  opens docA.doc for the first time. This lock file could contain things like user name etc. When another user wants to open docA.Doc the program first look for docA.loc. If docA.loc exists then you could read it and display a messagebox showing who has it open.
Code would be
If Dir$("c:\temp\docA.loc")<>"" Then
     'Read the lock file and display messagebox
End If

When the docA.doc is closed then the program would delete the lock file
0
 

Accepted Solution

by:
Ajoy earned 100 total points
ID: 1464024
you can use the key word app. This supports certain  properties out of which you can use the instance property.
if app.instance then don't run the file.
if this does not work then get back to me at atarafder@hotmail.com. i would be glad to help you
0
 

Author Comment

by:wsm
ID: 1464025
Ajoy,

I am not very sure what you are saying. Can you give a little bit more
details and example which I can look at?

I think raygibbins has given another good example. However, I do not wish to
create too many "temp" files just for this purpose, if possible.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 1

Expert Comment

by:raygibbins
ID: 1464026
My example is the similar to the way Microsoft and AutoDesk do it.
0
 

Author Comment

by:wsm
ID: 1464027
I notice that, but like I said before I do not wish to add any more "temp" files to the current directory. I have already added some other "temp" hidden files into that directory. Only when I cannot find any other solution to solve this then I will use this creating "temp" file.

I would really appreciate if you can give me any other ideas beside this one.
Thanx inadvance.
0
 

Expert Comment

by:Ajoy
ID: 1464028
wsm,
Before i can give you more details, Could you please tell me if your application is client/server based or a simple application.if your application isc/s based and the application runs on the server then what i said above can easily be implemented.
0
 

Author Comment

by:wsm
ID: 1464029
it is just a normal application that runs on win95. This should or might be a networked environment, but it is not a client/server application. If it is a networked environment, then those files are located at a shared directory
whereby users are allowed to access it. That is why I need some sort of codes
or function that will let people knows if that file is being used by another person.

 Hope u can understand what I am trying to say here.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question