Solved

VB Script read txt

Posted on 2011-09-15
5
448 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 53

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 53

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 53

Expert Comment

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

~bp
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check version 13 75
Modification on userform and column K 47 42
Visual Studio search word table and return Cell index 8 60
How to use odbc in vb to connect to ms sql 14 52
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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