Click to See Complete Forum and Search --> : conversion
netSurfer
Jan 28th, 2000, 03:45 AM
I need to read a linux text file in VB. THe problem is that Linux ends a line with hex(0A) and dos reads an end of line as hex(0A 0D). Is the any way in vb that I can switch this character. If I don't, it will read the entire file as 1 line. Since I have to seperate the lines this doesn't help me. I use perl right now but I'd like to have it all in one program.
As an option, is there a way I can run Perl in VB?
Mark Sreeves
Jan 30th, 2000, 08:26 PM
this should read the file into an array of strings
(I haven't tested it though!)
Private Sub Command1_Click()
Dim fnum As Long
Dim WholeFile As String
Dim char As String
Dim lines() As String
Dim i As Integer
Dim charPos As Integer
Open "TESTFILE" For Binary As fnum ' Open file.
WholeFile = Space(LOF(fnum))
Get fnum, , WholeFile
Close fnum
charPos = InStr(WholeFile, Chr(10))
While charPos <> 0
charPos = InStr(WholeFile, Chr(10))
ReDim Preserve lines(i + 1)
lines(i) = Left(WholeFile, charPos - 1)
'trim the text
WholeFile = Mid(WholeFile, charPos + 1)
i = i + 1
Wend
End Sub
------------------
Mark Sreeves
Analyst Programmer
Mark.Sreeves@Softlab.co.uk
A BMW Group Company
Mark Sreeves
Jan 30th, 2000, 08:28 PM
this should read the file into an array of strings
(I haven't tested it though!)
Private Sub Command1_Click()
Dim fnum As Long
Dim WholeFile As String
Dim char As String
Dim lines() As String
Dim i As Integer
Dim charPos As Integer
Open "TESTFILE" For Binary As fnum ' Open file.
WholeFile = Space(LOF(fnum))
Get fnum, , WholeFile
Close fnum
charPos = InStr(WholeFile, Chr(10))
While charPos <> 0
charPos = InStr(WholeFile, Chr(10))
ReDim Preserve lines(i + 1)
lines(i) = Left(WholeFile, charPos - 1)
'trim the text
WholeFile = Mid(WholeFile, charPos + 1)
i = i + 1
Wend
End Sub
------------------
Mark Sreeves
Analyst Programmer
Mark.Sreeves@Softlab.co.uk
A BMW Group Company
netSurfer
Jan 30th, 2000, 08:34 PM
I'll try that. Thanks. What exactly does it do? Does it read the whole file into a string and then divide it or does it take a piece at a time?
netSurfer
Jan 30th, 2000, 09:11 PM
It works great. I just dump lines() back into another file. I'm still wondering whether it dumps the entire file into memory (the string) or whether it only takes pieces of it.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.