Solved

VBscript, Sort Data, text file

Posted on 2008-10-01
8
2,202 Views
Last Modified: 2013-12-17
I have a list of data in a text file I want to sort in a specific format.
From this:
0101080030
0101080031
0101080032
0101080033
0101080034
0101080035
0101080040
0101080041
0101080042
0101080043
0101080044
0101080045
0101080050
0101080051
0101080052

To this:
0101080010,0101080011,0101080012,0101080013,0101080014,0101080015
0101080020,0101080021,0101080022,0101080023,0101080024,0101080025

The idea is to read each line, if the number ends in a '0' start a new line to a new text file in comma delimited format until you get another number that ends in a '0' then start a new line.

Any assistance appreciated.
0
Comment
Question by:TekNoxious
  • 3
  • 3
  • 2
8 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 22622647
Hmm. In JS it would be
str.replace(/\n/g,',').replace(/0,/g,'0\n')
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22623365
This should do it..

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
arrData = Split(objFSO.OpenTextFile("C:\Source.txt").ReadAll, vbNewLine)
Set objOutput = objFSO.CreateTextFile("C:\NewOutput.txt") 
x = 0
For Each strData in arrData
  x = x +1
  If x 6 7 Then
    objOutput.Write strData & ","
  Else 
    x = 0
    objOutput.WriteLine  strData
  End
Next 
objOutput.Close

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 22623491
what does

  If x 6 7 Then


mean???

Where is the test for the last digit being 0?
0
 

Author Comment

by:TekNoxious
ID: 22625695
I am with mplungjan about that line and missing function.
I would accept Jscript if that would make this an easier task. I am welcome to learning something new.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 67

Accepted Solution

by:
sirbounty earned 300 total points
ID: 22625910
Sorry - my rushed attempt before heading out the door...
This should work for you:
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objFile : Set objFile = objFSO.OpenTextFile("F:\Test.txt")

Dim objOutput : Set objOutput = objFSO.CreateTextFile("F:\New.txt")
 

Do While Not objFile.AtEndOfStream

  If strTemp = "" Then strTemp = objFile.ReadLine

    If Right(strTemp, 1) = "0" Then

      WriteLine strData

       strData = ""

      strData = strData & strTemp & ","

    Else

      strData = strData & strTemp & "," 

    End If

    strTemp = ""

Loop
 

WriteLine strData
 

objoutput.Close
 

Sub WriteLine (strData)

  If strData = "" Then Exit Sub

  End If

  objOutput.WriteLine Left(strData, Len(strData) -1)

End Sub

Open in new window

0
 

Author Comment

by:TekNoxious
ID: 22626534
The 'End If' needed to be removed from the Sub then it worked!
Thank you for the VBscript lesson.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22626557
accidental delete...originally
  If strData = "" Then
    Exit Sub
  End If

0
 

Author Closing Comment

by:TekNoxious
ID: 31502177
Thank you for your time and support.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now