+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
How do you do....it? Thread, Visual Basic in Technical; Hello, I am working on a small project and I have hit a birck wall.... All my google powers are ...
  1. #1

    Join Date
    Nov 2009
    Location
    Weymouth
    Posts
    37
    Thank Post
    1
    Thanked 3 Times in 3 Posts
    Rep Power
    10

    Question Visual Basic

    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!

  2. #2

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Silly thought, but have you tried with a plain old text file instead of with a DOCX file?

  3. #3

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,160
    Thank Post
    98
    Thanked 318 Times in 260 Posts
    Blog Entries
    4
    Rep Power
    111
    VB's not really my thing, but hopefully this link'll help you.

    Determine if a file is in use on server if not copy a file.

    I can't see anywhere in your code that you're actually checking if the file is open - just declaring a property. Trying to open it inside a try statement, and catching an exception if it's already open, should be a little more effective.

  4. #4

    Join Date
    Nov 2009
    Location
    Weymouth
    Posts
    37
    Thank Post
    1
    Thanked 3 Times in 3 Posts
    Rep Power
    10
    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

  5. #5

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    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.

  6. #6

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Wee I see VB jobs! 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

  7. #7

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by Hightower View Post
    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

    Code:
            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 -
    Quote Originally Posted by mgarland View Post
    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
    Last edited by Steve21; 19th April 2011 at 03:11 PM.

  8. #8

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,160
    Thank Post
    98
    Thanked 318 Times in 260 Posts
    Blog Entries
    4
    Rep Power
    111
    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.

  9. #9

    Join Date
    Nov 2009
    Location
    Weymouth
    Posts
    37
    Thank Post
    1
    Thanked 3 Times in 3 Posts
    Rep Power
    10
    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!!

  10. #10

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Quote Originally Posted by Steve21 View Post
    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.

  11. #11

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Quote Originally Posted by mgarland View Post
    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.

  12. #12

    Join Date
    Nov 2009
    Location
    Weymouth
    Posts
    37
    Thank Post
    1
    Thanked 3 Times in 3 Posts
    Rep Power
    10
    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.

  13. #13

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by mgarland View Post
    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

  14. #14

    Join Date
    Nov 2009
    Location
    Weymouth
    Posts
    37
    Thank Post
    1
    Thanked 3 Times in 3 Posts
    Rep Power
    10
    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

    DatabaseSECOND.zip

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

  15. #15

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    334
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by mgarland View Post
    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

    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

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Visual Basic Help
    By techie08 in forum How do you do....it?
    Replies: 0
    Last Post: 2nd November 2010, 03:29 PM
  2. More Visual Basic Help
    By mgarland in forum Coding
    Replies: 6
    Last Post: 28th June 2010, 02:09 PM
  3. Visual Basic 6 Help
    By mgarland in forum Coding
    Replies: 7
    Last Post: 28th June 2010, 10:17 AM
  4. Visual Basic 6
    By Samson in forum Windows
    Replies: 4
    Last Post: 30th August 2007, 12:41 PM
  5. Visual basic 6
    By Halfmad in forum Windows
    Replies: 9
    Last Post: 11th June 2007, 02:57 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •