Newsgroup: it.comp.lang.visual-basic
Titolo: Manipulating a Hugh text file (out of string space)

I'm using Visual Basic 6, the text file is like 10megs with 10
characters on each line
eg:
10000fffec
10010ffe8
1000ffe2
ect.
Currently, i have this:
Open "data.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, Strline
Loop
Close #1 
I get error 14 "Out of string space"
I need to perform an operation on each line which will be very easy to
implement as soon as i'm able to actually read it.
The error points to this line ->> Line Input #1, Strline
I can't see why it occurs as to my understanding it reads one line
into "Strline" then in the next loop it replaces whatever was in
Strline with the next line and so on.
So does Strline ever get any bigger than 10chars ?????
I also tried to read the whole text file into an array, but that
didn't work either
Any suggestions greatly appreciated...
Thanks.

 The error points to this line ->> Line Input #1, Strline
Is this file generated by UNIX or LINUX software? If the answer is yes, VB 
cannot handle  the file because newline chars are different from what VB 
expects. There are several programs able to translate from *NIX convention 
to DOS.
I used  xclrf.exe, you can search it using google, it's freeware.
You can also find the code needed to perform this task within VB, but with 
huge files is very slow: i.e. several minutes, while xcrlf.exe needs no 
more than 4 secs.
If the file is a DOS/windows file.... I have no idea
--
Call Me Ishmael

 ha scritto

qualcuno si ricorda quali sono i corrispondenti in mac e *n*x di vbcrlf ? mi
sembrava rispettivamente vblf e vbcr, ma non ne sono sicuro.
un replace via codice non dovrebbe essere difficile (string dovrebbe tenere
+-2 gb). ho appena fatto leggere un c:\dir.txt da 10.2 mb convertendo vbcrlf
in vbcr e vb non ha fatto una piega, anche se text1 ha troncato senza dire
niente la stringa risultante. non ho provato a buttare il risultato in un
file.
con taskman seguivo l'evoluzione del tutto. vb si e' preso un po' piu' di 50
mb.
j.

 *n*x di vbcrlf ? mi sembrava rispettivamente vblf e vbcr,
Esatto. vblf per Unix e vbcr per Mac.
Ciao. 
-- 
BSD is for UNIX-lovers -- linux is for Windows-haters.

 ha scritto

'several minutes' ? hmmm....
whenever i can i always like better handling all my needs from within the
code.
here is a sample for handling carriage returns with vb.
(thanks to our donald duck for the input routine :)
timing result follow the code:
Option Explicit
Const CR2 As String = vbCrLf & vbCrLf
Private Sub Command1_Click()
    Dim s As String, c As String
    Dim p As Long, fNum As Long, j As Long
    Dim time1
    time1 = Timer
    fNum = FreeFile
    Open App.Path & "\dir.txt" For Input As #fNum
    s = Input(LOF(fNum), fNum)
    Close #fNum
    p = InStr(s, vbCrLf)
    Text1 = Text1 & CR2 & p & " - " & Format(Timer - time1, "##0.000") &
vbCrLf
    Text1 = Text1 & CR2 & "----------------------------------  f1 - read"
    For j = 1 To 150
        c = Mid(s, j, 1)
        Text1 = Text1 & vbCrLf & Format(j, "000") & " - " & c & " - " &
Asc(c)
    Next
    time1 = Timer
    s = Replace(s, vbCrLf, vbLf)
    Text1 = Text1 & CR2 & "---------------------------------- f2 - write"
    For j = 1 To 150
        c = Mid(s, j, 1)
        Text1 = Text1 & vbCrLf & Format(j, "000") & " - " & c & " - " &
Asc(c)
    Next
    fNum = FreeFile
    Open App.Path & "\dir1.txt" For Output As #fNum
    Print #fNum, s;
    Close #fNum
    Text1 = Text1 & CR2 & FileLen(App.Path & "\dir.txt") & " - " &
FileLen(App.Path & "\dir1.txt") & _
        " - " & Format(Timer - time1, "##0.000")
    time1 = Timer
    fNum = FreeFile
    Open App.Path & "\dir1.txt" For Input As #fNum
    s = Input(LOF(fNum), fNum)
    Close #fNum
    Text1 = Text1 & CR2 & "---------------------------------- f2 - read"
    For j = 1 To 150
        c = Mid(s, j, 1)
        Text1 = Text1 & vbCrLf & Format(j, "000") & " - " & c & " - " &
Asc(c)
    Next
    time1 = Timer
    p = InStr(s, vbCrLf)
    Text1 = Text1 & CR2 & "vbcrlf: " & p & " - " & Format(Timer - time1,
"##0.000")
    time1 = Timer
    p = InStr(s, vbLf)
    Text1 = Text1 & CR2 & "vblf: " & p & " - " & Format(Timer - time1,
"##0.000")
    Close #fNum
    time1 = Timer
    s = Replace(s, vbLf, vbCrLf)
    Text1 = Text1 & CR2 & "---------------------------------- f3 - write"
    For j = 1 To 150
        c = Mid(s, j, 1)
        Text1 = Text1 & vbCrLf & Format(j, "000") & " - " & c & " - " &
Asc(c)
    Next
    fNum = FreeFile
    Open App.Path & "\dir2.txt" For Output As #fNum
    Print #fNum, s
    Close #fNum
    Text1 = Text1 & CR2 & FileLen(App.Path & "\dir.txt") & " - " &
FileLen(App.Path & "\dir1.txt") & " - " & FileLen(App.Path & "\dir2.txt") &
" - " & Format(Timer - time1, "##0.000")
End Sub
i tested it with a 10.5 megs textfile and the timing is like this:
(just skip to paste the char loop which i needed to look at the strings.)
35 - 1,992
----------------------------------  f1 - read
---------------------------------- f2 - write
10498846 - 10288868 - 6,617
---------------------------------- f2 - read
vbcrlf: 0 - 0,129
vblf: 35 - 0,000
---------------------------------- f3 - write
10498846 - 10288868 - 10498848 - 7,570
hth, j.
--
www.sundaysw.com

Ok, thanks heaps.
I downloaded the program
Just wonder tho
Surely there must have been a way for VB to recognize just LF ??


 Surely there must have been a way for VB to recognize just LF ??
james, i just posted the code for turning crlf to lf (or cr) and back to
crlf in a textfile up to 2 gb...
j.

 
si vabbè magari era un po' esagerato, però era un codice scaricato da 
chissà dove, non ottimizato, ed ora che ci penso (ehm... coff) ...beh..... 
lo facevo girare dal VB di excel, quindi era codice interpretato...
Ok,  come non detto... alla prossima...   :))
--
Andrea