Jump to content

Recommended Posts

Posted

Hello,

 

I am working on a small project and I have hit a birck wall.... All my google powers are not helping me.

 

I am an armature at visual basic and just can't see what I have done wrong!

 

So I just want to the script to know if a certain file is already in use. Here is what I have... It ALWAYS returns the "not open" msgbox

 

 

Public Class Form1

 

Private _fileOpen As Boolean

 

Private Property FileOpen(ByVal p1 As String) As Boolean

Get

Return _fileOpen

End Get

Set(ByVal value As Boolean)

_fileOpen = value

End Set

End Property

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If FileOpen("H:\Administration\Information Technology\Test.docx") = True Then

MsgBox("open")

Else

MsgBox("not open")

End If

End Sub

End Class

 

 

I have just attached it to a button with msgbox things to get it working... It will be doing something a bit more extravagant once I have the basics down.

 

If you need any more information please ask.

 

Thank you in advance. Sorry if I am being really dumb!

Posted

Well when I say I am new to this I mean very new.

 

I have done everything so far by just reading up on what I want to do.

 

I have so far managed to make a whole GUI for our equipment database complete with a search....

 

Only problem with this being that if more than one of you has the gui open it won't let you save any changes.

 

So I basically want to add a quick splash screen that only lets you into the GUI if it is not in use, this should eliminate the issue.

 

But my VB + programming knowledge is next to nothing. I am a technician not a programmer :(

Posted

If FileOpen("H:\Administration\Information Technology\Test.docx") = True Then

 

As far as I can see this function actually opens a file, rather than telling you if a file is currently open elsewhere.

Posted

Wee I see VB jobs! :D you still stuck on the checking if file open part? or got past that?

 

And why exactly do you want to check if it's open? :p Sure there's a way around whatever yuou're looking at!

 

Steve

Posted (edited)
As far as I can see this function actually opens a file, rather than telling you if a file is currently open elsewhere.

 

^ As HT says, You're not asking if it's open. You're asking it to FileOpen is true. Thus nonsense :p

 

What you need to do if try to open the file in exclusive mode (aka only you can open).

 

If it returns with an error, you can determine if it's an error error, or someone else has it open error.

 

Although I don't have a working VB studios here, this "should" work

 


       Dim NameOfFile As String = TextBox1.Text

       Try
          
           Dim MyFileStream As IO.FileStream = IO.File.Open(NameOfFile, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
           
           MyFileStream.Close()
           MyFileStream.Dispose()
           MyFileStream = Nothing

           MessageBox.Show("No-one has this open.")

       Catch ex As IO.IOException
            MessageBox.Show("Someone has this open.")

       Catch ex As Exception
           MessageBox.Show("Error.")

       End Try

 

1) Takes name from textbox (or however you're inputting)

2) Tries to open the file in exclusive mode

3) Either returns success, error as someone has opened, or error error

 

*Edit -

Only problem with this being that if more than one of you has the gui open it won't let you save any changes.

 

So I basically want to add a quick splash screen that only lets you into the GUI if it is not in use, this should eliminate the issue.

 

How are you opening/saving it? Shouldn't cause any issue AT ALL just with the GUI open, unless you're opening the file and never closing it during whole process?

 

Steve

Edited by Steve21
Posted

Is your equipment database constructed using flat files?

 

You may find it easier to actually go a little more advanced, and use something like Lightswitch to construct a SQL database with GUI rather than locking people out if someone else has the file open.

Posted

So many questions so little knowledge! I am clueless....

 

I will just explain exactly what I am trying to do.

 

So we have a database here with our equipment in. Made in Access so it is a .dbm file or w/e

 

I have made a GUI that uses that file as a data source to display the equipment in like a form would in access.

 

The issue we are having is that if one person has the program open when another person has there is no warning at all. Until someone wants to save.... As you can imagine this is a pain if for example I have added some things and so has a colleague because we will not be able to save the file.

 

So what I wanted to do was pop in a quick form that opens first and only lets you move onto the database form if no one else has it open. In the hope that this will avoid the problem.

 

Am I making myself clear?

 

Thank you all for your input. Please answer me assuming no prior VB knowledge or programming knowledge. I am a techie "having a go" eeeek!!

Posted
How are you opening/saving it? Shouldn't cause any issue AT ALL just with the GUI open, unless you're opening the file and never closing it during whole process?

 

I was thinking this as well. It would be better if the OP changed it so the file opened, got all the data needed at that time into the program and closed the file. That way the file would only be open for a fraction of a second.

Posted
So many questions so little knowledge! I am clueless....

 

I will just explain exactly what I am trying to do.

 

So we have a database here with our equipment in. Made in Access so it is a .dbm file or w/e

 

I have made a GUI that uses that file as a data source to display the equipment in like a form would in access.

 

The issue we are having is that if one person has the program open when another person has there is no warning at all. Until someone wants to save.... As you can imagine this is a pain if for example I have added some things and so has a colleague because we will not be able to save the file.

 

So what I wanted to do was pop in a quick form that opens first and only lets you move onto the database form if no one else has it open. In the hope that this will avoid the problem.

 

Am I making myself clear?

 

Thank you all for your input. Please answer me assuming no prior VB knowledge or programming knowledge. I am a techie "having a go" eeeek!!

 

As a 'techie having a go' I would suggest your best bet is to use Access for the whole thing, to simplify it for yourself. Create a form in Access to do what you are doing in VB.net.

 

Then, if you want to allow multiple connections to the Access you can separate the front-end (forms) from the back-end (data) quite easily with an Access feature.

Posted

Well HT that is a very defeatist attitude! haha

 

I have got every other feature we need working including filters to search and all sorts of other fancy things...

 

Just this one last bit and I have made my first programme! I don't really want to admit defeat here. I hate asking for help but sometimes you have to know your limits.

 

I could upload the project files somewhere if that would help.

Posted
The issue we are having is that if one person has the program open when another person has there is no warning at all. Until someone wants to save.... As you can imagine this is a pain if for example I have added some things and so has a colleague because we will not be able to save the file.

 

So what I wanted to do was pop in a quick form that opens first and only lets you move onto the database form if no one else has it open. In the hope that this will avoid the problem.

 

 

Honestly, Without sounding rude, it sounds like the design of the "opening file" is a bit silly. As HT mentioned all you need to do is open the file, pull any data. Close it. And thus with saving, open, edit, close.

 

If "as I expect" you are doign, You open it program start, then close it when you close the program that's where the issue arrives. You're leaving the file open, when no-one is doing anything to it, and this in turn locks out anyone trying to edit it. (think of it as leaving the phone off the hook)

 

Any chance you could post a copy of the form up for us to take a look?

 

Steve

Posted

Ok I posted up the whole project on media fire....

 

Please remember I am kinda learning as I go. This might be a bit of a mess.... But it all seems to work ok for us with this slight hicup.

 

I am desperate to get it done before Easter weekend :D

 

DatabaseSECOND.zip

 

Thank you for any time you put into looking over this for me.

Posted
Ok I posted up the whole project on media fire....

 

Please remember I am kinda learning as I go. This might be a bit of a mess.... But it all seems to work ok for us with this slight hicup.

 

I am desperate to get it done before Easter weekend :D

 

DatabaseSECOND.zip

 

Thank you for any time you put into looking over this for me.

 

Any chance just to stick the forms up (attach to the post)? The exe is blocking it through SWGFL, and don't have proxy login where I am currently.

 

Steve

Posted

In the project folder there's a form1.VB (Or whatever your first form is called)a ka where your code is :p

 

or PM me the code, either way works!

 

Steve

Posted
Well HT that is a very defeatist attitude! haha

 

It's not defeatist at all. As an IT Professional it is important to choose the right tools to do the job. I'm not saying you've made the wrong choice with VB.net, but you've kind of bought a car to race a sprinter. If Access can do everything you need it to do, use it - after all, that's why those features are written in. Why learn fluent Spanish if all you need is to order a beer quickly. ;)

Posted
It's not defeatist at all. As an IT Professional it is important to choose the right tools to do the job. I'm not saying you've made the wrong choice with VB.net, but you've kind of bought a car to race a sprinter. If Access can do everything you need it to do, use it - after all, that's why those features are written in. Why learn fluent Spanish if all you need is to order a beer quickly. ;)

 

To make sure you get premium beer, not some knock off!!! I mean, VB yes :getmecoat:

(Still looking for that source code :p But guess I could download it at home later, seeing it's nearly hometime! hurrah)

 

Steve

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...