SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 9 of 9
  1. #1
    Member
    Join Date
    Feb 2012
    Posts
    74
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    VBScript - Issue - Bad file mode

    Hi All,

    I am facing a weird issue with my vbscript. My vbscript interpreter was working fine till the day I decided to install visual svn server for verifying purpose.

    Currently when I open a file in read mode everything works fine. But when I open in write mode & try to read the data there is an error called Bad File Mode which pops up.
    Is it that when we open a file in write mode - we can't read the data - I am very skeptical about this . I have googled a bit and also browsed thread , but most of the results pointed me towards permission issue . I have verified with the systems group here & I have all the permission including admin rights ..


    Code:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTSO = objFSO.OpenTextFile(sFilePath,2,false)'This line when put in watch shows Permission error
    sFileData=objTSO.ReadAll ' This line shows Bad file mode error.

    Am i missing something here .

    Any pointers appreciated.

    Regards,
    Kartik
    If you do find solution to a problem - have a bud & re-visit !

  2. #2
    Moderator
    Join Date
    Oct 2010
    Location
    Norway
    Posts
    3,265
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: VBScript - Issue - Bad file mode

    [ QUOTE ]
    But when I open in write mode & try to read the data there is an error called Bad File Mode which pops up.
    Is it that when we open a file in write mode - we can't read the data

    [/ QUOTE ]

    Yes, you have to open in read mode to read.
    Rajkumar

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    74
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: VBScript - Issue - Bad file mode

    Thanks for reply rajakumar . I find it pretty skeptical even after using VBScript for almost 3 years I was unaware of this fact . Issue is resolved.. Created a different write stream for the same file .

    Regards,
    Kartik G Pai
    If you do find solution to a problem - have a bud & re-visit !

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: VBScript - Issue - Bad file mode

    '2 is for writing
    CONST ForReading=1

    Set objTSO = objFSO.OpenTextFile(sFilePath,ForReading,false)

  5. #5
    Member
    Join Date
    Feb 2012
    Posts
    74
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: VBScript - Issue - Bad file mode

    Thanks for the input ruby . I was skeptical as to when a file is opened in write mode why can't it read it . I gathered this issue when I had to read and write the same file . I tried to use a single text stream object , hence the error.
    If you do find solution to a problem - have a bud & re-visit !

  6. #6
    Junior Member
    Join Date
    May 2012
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: VBScript - Issue - Bad file mode

    'use ForAppending=8
    CONST ForAppending=8

    Set objTSO = bjFSO.OpenTextFile(sFilePath,ForAppending,false)


    ForReading 1 Opens a file for reading only
    ForWriting 2 Opens a file for writing. If the file already exists, the contents are overwritten.
    ForAppending 8 Opens a file and starts writing at the end (appends). Contents are not overwritten.

  7. #7
    Member
    Join Date
    Dec 2007
    Location
    Makati City, Manila
    Posts
    71
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: VBScript - Issue - Bad file mode

    [ QUOTE ]
    I was skeptical as to when a file is opened in write mode why can't it read it . I gathered this issue when I had to read and write the same file . I tried to use a single text stream object , hence the error.

    [/ QUOTE ]

    you can't read on a write mode because the data you want to retrieved is locked to write mode only. the principle applied is the same with oracle database where there's a record locked and save point.
    .
    .
    .
    Cheers,

    Reynald S. Geonson


    <font color="gray">You can teach a student a lesson for a day; but if you can teach him to learn by creating curiosity, he will continue the learning process as long as he lives. - Clay P. Bedford</font>
    .
    CLICK HERE... another set of skill i possessed

  8. #8
    Member
    Join Date
    Feb 2012
    Posts
    74
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: VBScript - Issue - Bad file mode

    Thanks for the input rey .
    If you do find solution to a problem - have a bud & re-visit !

  9. #9
    Member
    Join Date
    Dec 2007
    Location
    Makati City, Manila
    Posts
    71
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: VBScript - Issue - Bad file mode

    @kartikpai

    anytime bro! [img]/images/graemlins/smile.gif[/img]
    .
    .
    .
    Cheers,

    Reynald S. Geonson


    <font color="gray">You can teach a student a lesson for a day; but if you can teach him to learn by creating curiosity, he will continue the learning process as long as he lives. - Clay P. Bedford</font>
    .
    CLICK HERE... another set of skill i possessed

 

 

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 10.00%
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:27 AM.

Copyright BetaSoft Inc.