Solved

VB Script read txt

Posted on 2011-09-15
5
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 55

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 55

Accepted Solution

by:
Bill Prew earned 500 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 55

Expert Comment

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

~bp
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

719 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