SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    SQA Knight bklabel1's Avatar
    Join Date
    Sep 2012
    Location
    Kew Gardens, United States
    Posts
    2,596
    Post Thanks / Like
    Blog Entries
    1
    Mentioned
    2 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0

    permission denied

    Every once in the while, the scirpt that I'm working on locks up. The error message is permission denied. The code is below:

    I log off and back on , open QTP , open the script. Then the file opens again.

    I don't have the file open any place on the desk top. I don't know what has the handle of the file open.

    Is there a way to get to use the file again without having to log/off and all the other things?

    Code:
       Dim fso, MyFile
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set MyFile = fso.CreateTextFile(txtFile, True, False)  <-- permission denied

  2. #2
    Advanced Member
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    742
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Are you closing the fileObject and textstreamobject after use.

    MyFile.Close

  3. #3
    SQA Knight bklabel1's Avatar
    Join Date
    Sep 2012
    Location
    Kew Gardens, United States
    Posts
    2,596
    Post Thanks / Like
    Blog Entries
    1
    Mentioned
    2 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0
    I set
    fso = Nothing
    MyFile = Nothing

    at the end of the function.

    Is MyFile, in my code above, the same thing as textStreamobject? I think they are. Not sure.

    I don't know what makes it lock up. Once it does, is there anything that I can do besides log off / on?

    Any processes to close, handles to remove? That sort of thing?

    Thanks,

    Kevin

  4. #4
    Advanced Member
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    742
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Are you closing the file object?

  5. #5
    SQA Knight bklabel1's Avatar
    Join Date
    Sep 2012
    Location
    Kew Gardens, United States
    Posts
    2,596
    Post Thanks / Like
    Blog Entries
    1
    Mentioned
    2 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0
    Yogi,
    I believe that I am closing the file object with
    fso = Nothing. Please see my code above.
    Thanks,

    Kevin

  6. #6
    Advanced Member
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    742
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Nothing is to tell Mr. garbage collector that memory is ready for him to collect and reuse. Close is to close the connection but not release the memory, and Mr. Garbage collector {like system.gc(in java)} will not take any cognizance of that.


    Am I understanding correct this in VBS?

  7. #7
    SQA Knight bklabel1's Avatar
    Join Date
    Sep 2012
    Location
    Kew Gardens, United States
    Posts
    2,596
    Post Thanks / Like
    Blog Entries
    1
    Mentioned
    2 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0
    Yes it is in VBSCript in a QTP library. The function works most of the time. Every once in the while it says that there is a restriction. The file is on my C: drive so I do not know what is wrong. Logoff / on PC fixes it.

    Let us say that the handle was left open. Maybe the scirpt stops before it has a chance to tell Mr. Garbage collector that we do not need the object any more. Say it is stuck in memory. Is there a way to kill the object later on?

    Am I missing the point of something that you are telling me to do and I am not try it?

    Thanks,

    Kevin

  8. #8
    Advanced Member Anshoo Arora's Avatar
    Join Date
    Oct 2007
    Location
    New Delhi, India
    Posts
    635
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Try using this:

    Code:
    Const ForReading = 1
    Const ForWriting = 2
    Const ForAppending = 8
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Set MyFile = Nothing
    
    On Error Resume Next
        Set MyFile = fso.OpenTextFile(txtFile, ForWriting, True)
    	
        If Err.Number <> 0 Then
            Set MyFile = fso.GetFile(txtFile)
        End If
    On Error Goto 0
    
    If MyFile Is Nothing Then
        'MyFile was not created..
    End If
    
    Set fso = Nothing
    Any luck?
    Last edited by Anshoo Arora; 05-09-2013 at 12:46 PM.
    Regards,

    Anshoo Arora
    Relevant Codes

  9. #9
    SQA Knight bklabel1's Avatar
    Join Date
    Sep 2012
    Location
    Kew Gardens, United States
    Posts
    2,596
    Post Thanks / Like
    Blog Entries
    1
    Mentioned
    2 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0
    Anshoo,
    I have a question before trying the code.

    Set Myfile = Nothing

    What if the object does not already exist. Wont QTP say something such as I am referencing a variable that does not exist? I think that I have seen this in the past.

    Thanks,

    Kevin

  10. #10
    Advanced Member
    Join Date
    May 2006
    Location
    United Kingdom
    Posts
    742
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

 

 
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
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 06:51 PM.

Copyright BetaSoft Inc.