Computing.Net > Forums > Programming > Vb script help

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Vb script help

Reply to Message Icon

Original Message
Name: keeprockin
Date: August 21, 2007 at 00:27:22 Pacific
Subject: Vb script help
OS: windows NT
CPU/Ram: pentium 3 and 256 MB ram
Comment:

Hi, i am new to scripting , and i am facing one problem.

i have one csv file and it contains few records.

what i need to do is to write a script(vbscript or batch file), which can delete third comma wherever it appears in a line from every record of this file.

please if some one can help me out in writing this code.


Report Offensive Message For Removal


Response Number 1
Name: Razor2.3
Date: August 21, 2007 at 04:44:11 Pacific
Reply: (edit)

Well, if no one else is gonna grab this one...

WScript.Quit Main("Test.txt")

Function Main(sFile)
Dim sTName, sLine, oFSO, fTmp, iComma
Main = 0

Set oFSO = CreateObject("Scripting.FileSystemObject")
sTName = oFSO.GetTempName
Set fTmp = oFSO.CreateTextFile(sTName, True)
With oFSO.OpenTextFile(sFile, 1, False)
Do Until .AtEndOfStream
sLine = .ReadLine
iComma = FindThird(sLine, ",")
If iComma Then
fTmp.Write Left(sLine, iComma - 1)
fTmp.WriteLine Right(sLine, Len(sLine) - iComma)
Else
fTmp.WriteLine sLine
End If
Loop
End With
fTmp.Close
oFSO.DeleteFile sFile, True
oFSO.MoveFile sTName, sFile
End Function

Function FindThird(sIn, sComp) 'As Integer
On Error Resume Next
Dim i, start
FindThird = Null
start = 0
For i = 1 To 3
start = InStr(start + 1, sIn, sComp, 0)
Next
If Not Err Then _
FindThird = start
End Function



Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software