Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Script read txt

Posted on 2011-09-15
5
Medium Priority
?
473 Views
Last Modified: 2012-05-12
I have a need to open a txt file and then generate multiple files from it. this is a sample of what each line looks like, "31997869692",8/19/2011,"BAKR,CH R" the only thing that matters is the first number without the quotes. this number needs to be wrote to a file and then saved with the name being the number.RSD the extension has to be caps.

I do not know how to do this, I have an input box for the file name, that is about as far as I can get
dim strfile

  strfile = InputBox("Please enter file name", "File Info", ,100 ,200)
   WScript.Echo strfile

Open in new window

sample.txt
0
Comment
Question by:hoshie329
  • 3
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Bill Prew
ID: 36545860
I'm a little confused, since the first number without quotes is a date, and repeats many times for the same value.  So you'd be writing the same file over and over, is that the intention?  Or if the field really the very first number on the line, like: 14997177449.RSD.

~bp
0
 

Author Comment

by:hoshie329
ID: 36545880
it is the second example 14997177449.RSD. Thank you
0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 36545971
Give this a try, I think it's close to what you described.

Const cForReading = 1
Const cForWriting = 2

sInFile = InputBox("Please enter file name", "File Info", ,100 ,200)
WScript.Echo sInFile

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oInFile = oFSO.OpenTextFile(sInFile, cForReading)

Do Until oInFile.AtEndOfStream
    sCurrentLine = oInFile.Readline
    aFields = Split(sCurrentLine , ",")
    sCurrentKey = aFields(0)
    sCurrentKey = Replace(sCurrentKey, """", "")
    Set oOutFile = oFSO.OpenTextFile(sCurrentKey & ".RSD", cForWriting, True)
    oOutFile.WriteLine(sCurrentKey)
    oOutFile.Close
Loop

oInFile.Close

Open in new window

~bp
0
 

Author Closing Comment

by:hoshie329
ID: 36546044
This works perfectly, great solution. Thanks
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 36546076
Great, glad that worked out.

~bp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question