Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have VBA code that changes a file's attribute from vbHidden to vbNormal and then proceeds to the next line of code.

    My challenge is that the code continues prior to the file attribute is changed. This is simply a timing issue. How does one prevent the code from continuing until the file attribute changes?

    Thanks,
    John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Does it help if you insert a line

    DoEvents

    between the two instructions?

    If not, you could insert a loop

    Code:
    Do While (file is hidden)
      DoEvents
    Loop

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans,

    It's still happening.

    My code example is:

    [codebox]'File Attributes
    FileAttribute = GetAttr(sPathOfSourceFile & strFileName) And vbHidden

    If FileAttribute = 2 Then
    SetAttr (sPathOfSourceFile & strFileName), vbNormal
    Do While GetAttr(sPathOfSourceFile & strFileName) <> 0
    DoEvents
    Loop
    End If
    [/codebox]

    Regards,
    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I'm sorry, I can't explain that. What happens if you single-step through the code?

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='794207' date='20-Sep-2009 22:40']I'm sorry, I can't explain that. What happens if you single-step through the code?[/quote]


    Stepping through the code provides enough time for the file attribute to change. All other lines of code run as expected.

    Seem to be a timing difference in seconds.

    Regards,
    John

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    That was to be expected. But I still don't understand why the Do While loop doesn't work...

Posting Permissions

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