Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Strange Rename behaviour (VB6)

    I am using the code below in a Form_Unload procedure. It works as expected, unless I remove the MsgBox line, in which case the .tmp file remains intact, and the existing .ini file appears to be overwritten with garbage. Even if I replace the MsgBox with "RetVal = ..." I still get the same erroneous result. Any ideas please?
    <code>
    Kill CurDir & "List.bak"
    Name CurDir & "List.ini" As CurDir & "List.bak"
    MsgBox Dir(CurDir & "List.tmp")
    Name CurDir & "List.tmp" As CurDir & "List.ini"
    </code>

    Alan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Strange Rename behaviour (VB6)

    It's probably a timing issue. Replacing MsgBox with a delay loop will most likely do the job too.

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange Rename behaviour (VB6)

    <P ID="edit" class=small>(Edited by AlanMiller on 10-Apr-05 22:10. )</P>Thanks Hans. This is deja vu re: my <post#=464298>post 464298</post#> and your reply. I'll try the loop trick again.

    Alan

    Nope <img src=/S/nope.gif border=0 alt=nope width=15 height=15>. No luck with delay loops I'm afraid. Any other workarounds?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Strange Rename behaviour (VB6)

    Did you put DoEvents inside the delay loop?

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Strange Rename behaviour (VB6)

    My name isn't Hans, but how are you checking to insure that list.tmp exists? You're trying to rename it, but what creates it? If it isn't fully written when you try to rename it, the Name operation will interrupt the write and leave you with garbage. Could that be part of your problem?
    Charlotte

  6. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange Rename behaviour (VB6)

    Hi Not Hans

    The .tmp file is created with a quick bit of scripting:
    <code>
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile(CurDir & "List.tmp", True)
    a.Close
    </code>
    I then write everything I need to it using the API function PutINIValue.
    The .tmp file is always in good order when it "sticks" and the .ini is messed up.
    When the .ini is overwritten as planned, it is also in good order.

    The only check I make is the delay loop condition:
    Do Until Dir(CurDir & "List.tmp") <> ""

    I can't think of any other way to "check up" on its status.

    Alan

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange Rename behaviour (VB6)

    <P ID="edit" class=small>(Edited by AlanMiller on 11-Apr-05 21:31. )</P>I used the "Sleep" API subroutine and it didn't matter how long I set it for, the result was the same. I didn't try DoEvents because (I believe) it chews lots of CPU, and I thought that might largely negate the purpose of its inclusion in this case. I'll give it a shot now though, since nothing else seems to work.

    When I use a loop condition like :
    Do Until Dir(<filename>) <> ""

    it doesn't seem to be getting to the heart of the problem i.e. the Dir command seems to respond correctly straight away, but the initial problem remains. Can you suggest any alternatives Hans?

    Alan

    Hans, I just tried the implementation of this DoEvents Function Example, but without luck.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Strange Rename behaviour (VB6)

    Do the links in <post#=431634>post 431634</post#> help?

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Strange Rename behaviour (VB6)

    The trouble with that is that a file exists as soon as you create it and start writing to it. I may be zero bytes, but it exists. We ran into similar problems with one of our applications, trying to figure out whether a file was completely written yet. We resorted to trying to copy the file, since we discovered that we could not do so from within Access if the file was still in the process of being written.
    Charlotte

  10. #10
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange Rename behaviour (VB6)

    Well, they do seem to point to something funny, Hans. When I include the FileAlreadyOpen function in my code (as below but without the bold line) the last line generates a "File already exists" error. The "INI already open" message does not appear, but there is indeed a zero byte List.ini file. However, without the FileAlreadyOpen check, it sails through no problem. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    <code>
    Kill CurDir & "List.bak"
    Name CurDir & "List.ini" As CurDir & "List.bak"
    If FileAlreadyOpen(CurDir & "LaunchList.ini") Then _
    MsgBox "INI Already Open."
    MsgBox "Here"
    Kill CurDir & "LaunchList.ini"
    Name CurDir & "List.tmp" As CurDir & "List.ini"
    </code>

    Finally, I inserted the Kill (bold code) and it appears to work as it should without the msgbox. [Edited] at least I thought it did. <img src=/S/nope.gif border=0 alt=nope width=15 height=15> still need that innocuous msgbox! Still <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

    Alan

  11. #11
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange Rename behaviour (VB6)

    Glad to hear it happens to the monarchy too... not just us commoners <img src=/S/wink.gif border=0 alt=wink width=15 height=15>. But I don't quite follow what you're saying here. Did resorting "to trying to copy the file" somehow circumvent the problem?

    Alan

  12. #12
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Strange Rename behaviour (VB6)

    I know I'm just a commoner but...

    If the process that is writing the file hasn't yet finished
    Then the file copy will fail
    End If

    If the file copy succeeds
    Then the process that was writing the file has finished
    End If

    StuartR

  13. #13
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange Rename behaviour (VB6)

    Thanks Stuart. I was thinking along these lines, and I'll certainly try more testing using this as an indicator. Trouble seems to be though, that the offending file remains "hung" (open for write) until that msgbox command is run, after which things start to behave as expected. That is, I think the copy will just continue to fail unless the msgbox executes. I'll give it a try.

    Alan

  14. #14
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Strange Rename behaviour (VB6)

    Stuart has figured out the royal logic and is hereby enobled, so you can curtsey to him. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> Our app goes about its business and then comes back after a set interval and tries to copy the file again to a temp location. Once it can be copied, we know the file has been completely written. In our case, a communications program is writing the file, so it comes in a bit (no pun intended) at a time. If your file remains open, then I would look at the code that is writing it, because there needs to be a close in there somewhere. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

  15. #15
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange Rename behaviour (VB6)

    I've been giving that file closure some thought (although I'm sure you thought of it first, being a queen & all <img src=/S/grin.gif border=0 alt=grin width=15 height=15>). Normally I'd be explicitly closing the file after writing, but in this case I'm using the API:
    x = WritePrivateProfileString(sSection$, sEntry$, sString$, sFileName$)

    This doesn't use an explicit "Open", and logically there is no room/ need for an explicit "Close". I'm wondering if there's some hang or delay inherent in this API method?

    Alan

Page 1 of 2 12 LastLast

Posting Permissions

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