Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove commas from a text file

Status
Not open for further replies.

Timinator

Programmer
Apr 13, 2001
33
US
I am trying to input data from a text file that is created from a different program. The problem that i have run into is that some numbers in the text file have commas(ex: 1,400). The program reads that comma as being the end of that record, so it moves to the next line. Is there a way to remove all commas from the text file?
 
Private Sub Command1_Click()
' Declare necessary variables
' ***** Note - Add a reference to Microsoft Scripting Runtime
Dim FileSystemObject, InStream As Object, OutStream As Object
Dim InputData As String

' Create a reference to the FileSystemObject
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

' Create Input Data Stream
Set InStream = FileSystemObject.OpenTextFile("C:\Test.txt", ForReading, False, TristateFalse)

' Create Output Data Stream
Set OutStream = FileSystemObject.CreateTextFile("C:\Test2.txt", True)

' Loop through the entire file
Do While InStream.AtEndOfStream <> True
InputData = InStream.ReadLine
InputData = Replace(InputData, &quot;,&quot;, &quot;&quot;)
OutStream.WriteLine InputData
Loop

' Closes all streams
InStream.Close
OutStream.Close

' Prompts user when program has finshed
MsgBox &quot;Done!&quot;, vbInformation
End Sub Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top