Solved

VBscript, Sort Data, text file

Posted on 2008-10-01
8
2,297 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
[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
  • 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
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!

 

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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

This article was originally published on Monitis Blog, you can check it here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sourc…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

737 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