vbscript query

  • need help with vbscript code to read specific number of characters from a text file and save them to another file

    For example : read all the characters from 10th character to the 20th character and write these characters to another text file

    I know its simple but i cant seem to figure it out.

    code needs to be in vbscript not vb6 or .net

    Can anybody help?

    Thanks

  • is that characters 10 thru 20 of the whole file, or 10 thru 20 for each row/line in the file? so if the file has 120 lines, you need a table with that many results?

    dim fsoobj ' As FileSystemObject

    dim strobj ' As FileStream

    dim FileContents ' As String

    dim CurrentRow ' As String

    Set fsoobj = CreateObject("Scripting.FileSystemObject")

    '1 = ForReading, 2 = ForWriting, 8 = ForAppending

    Set strobj = fsoobj.OpenTextFile("c:\Data\toys.txt",1)

    FileContents = strobj.ReadAll

    strobj.Close

    'get the string

    CurrentRow = mid(FileContents,10,10)

    'now write the file True =Create if not exists

    Set strobj = fsoobj.OpenTextFile("c:\Data\anewfile.txt",2,True)

    strobj.WriteLine CurrentRow

    strobj.Close

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks dude

  • Lowell (11/25/2010)


    is that characters 10 thru 20 of the whole file, or 10 thru 20 for each row/line in the file? so if the file has 120 lines, you need a table with that many results?

    dim fsoobj ' As FileSystemObject

    dim strobj ' As FileStream

    dim FileContents ' As String

    dim CurrentRow ' As String

    Set fsoobj = CreateObject("Scripting.FileSystemObject")

    '1 = ForReading, 2 = ForWriting, 8 = ForAppending

    Set strobj = fsoobj.OpenTextFile("c:\Data\toys.txt",1)

    FileContents = strobj.ReadAll

    strobj.Close

    'get the string

    CurrentRow = mid(FileContents,10,10)

    'now write the file True =Create if not exists

    Set strobj = fsoobj.OpenTextFile("c:\Data\anewfile.txt",2,True)

    strobj.WriteLine CurrentRow

    strobj.Close

    Hi Lowell,

    Am I reading that correctly? Does it read the entire file first? I'm asking because if you need to read the kind of files I typically have to work with (more than 10GB is typical), I beleive the system is going to become a little starved for memory. Wouldn't a read-1, write-1 methodology be better?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • The problem is that the parameter prompt still pops. I am beginning to wonder if this does not work in Access 2003? I have seen severla post with people asking the same question with no good answer. Maybe a Microsoft developer would know? Thanks!

    Online shopping at Chinabuye for dropship electronics[/url] Service

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply