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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting file to Tect-MS DOS Format

Status
Not open for further replies.

coughnut

Programmer
Dec 6, 2005
27
US
I am searching for help once again. What I want to do is convert a certain file to a .txt Document MS-DOS Format. The file that I need to convert is coming from a Solaris machine, I want to parse that file and search for certain Item in order to construct a table. The thing is that when I use VBA to read the file line by line, I use the While(Not(EOF(fileHandle))), windows sees the file as one huge line, when in reality the file has 672 lines.

What I found out is that if I open the file using WordPad and save the Document as a Text Document-MS-Dos Format I am able see all the lines in the file. So what I am I need to know is if there is a way to convert a file to a Text Document-MS-Dos Format. So far I can create a txt document of the file that came out of the Solaris machine. But this is not enough, the file is still viewed as one big line. Here is what I have so far:

Function ConvertToTxt(strPath As String)

Dim objFileSystem
Dim objFile
Dim strFileCopy As String
Dim intExtPosition As Integer

'--- Create an instance of the FileSystemObject to access
'the local file system
Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'---Use the GetFile method to return a File object corresponding to the
' file in a specified path.
Set objFile = objFileSystem.GetFile(strPath)
intExtPosition = InStr(objFile.Name, ".")
If intExtPosition > 0 Then
strFileCopy = Left(objFile.Name, intExtPosition - 1) & "Copy.txt"
Else
strFileCopy = objFile.Name & "Copy.txt"
End If

'---Create a copy of the file with a .txt extension
objFile.Copy strFileCopy, True
lineRead = ReadWizardFile(strFileCopy)
MsgBox "Lines Read: " & lineRead & "", vbOKOnly

End Function

Thanks for all your help....
 
That's one of the reasons I started using methods of the filesystemobject and textstream some years ago for test file manipulation.

[tt]dim txt as object ' or scripting.textstream
dim strLine as string
set txt = objFileSystem.opentextfile(strFileCopy, 1) ' 1 - ForReading
do while not txt.atendofstream
strLine = txt.Readline
debug.print strLine
' do lot of interesting stuff ...
loop
txt.close
set txt = nothing[/tt]

- typed not tested ...

Roy-Vidar
 
I am not familiar with filesystemobjec and I get an error when trying the above code. I get :Run Time Error '424' Object Required. It happens here: Set txt = objFileSystem.opentextfile(strFile, forReading) ' 1 - ForReading
 
coughnut,

probably you forgot the following lines

Dim objFileSystem
'--- Create an instance of the FileSystemObject to access
'the local file system
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top