ghost reading file

gmadeira

Member
Joined
Sep 8, 2010
Messages
9
Programming Experience
Beginner
Hi folks. I'm having some problem here. I have a list of files to read and have to append them all to one unique file. the problem is that when i open the first file to read. I read the first line and discard it. when i read the second line, its empty ! but it is not in the original file. what im doing wrong ? tks for the help

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGera.Click
Dim QtdPapeis As Integer
Dim I As Integer
Dim oWrite As System.IO.StreamWriter
Dim oRead As System.IO.StreamReader
Dim caminho As String

oWrite = IO.File.CreateText("c:\ibov\carga.txt")
QtdPapeis = PF.SecurityCount() - 1
For I = 0 To QtdPapeis
caminho = "c:\ibov\" & PF.Security(I).GetSymbol & ".txt"
oRead = New System.IO.StreamReader(caminho)
GeraCargaTabelaQuotes(oRead, oWrite)
oRead.Dispose()
Next
oWrite.Dispose()
End Sub

Public Sub GeraCargaTabelaQuotes(ByVal arq_origem As System.IO.StreamReader, ByVal arq_destino As System.IO.StreamWriter)
Dim linhaAtual, linhaescrever, cod, desc, periodo, data, hora, open, high, low, close, volume, interest As String
Dim strArray() As String
linhaAtual = arq_origem.ReadLine() 'pula a 1a linha
linhaAtual = arq_origem.ReadLine()
While (Not arq_origem.EndOfStream)
strArray = linhaAtual.Split(",")
cod = strArray(1)
desc = strArray(2)
periodo = strArray(3)
data = strArray(4).Substring(0, 4) & "-" & strArray(4).Substring(4, 2) & "-" & strArray(4).Substring(6, 2)
hora = strArray(5)
open = strArray(6)
high = strArray(7)
low = strArray(8)
close = strArray(9)
volume = strArray(10)
interest = strArray(11)
linhaescrever = cod & ";" & desc & ";" & periodo & ";" & data & ";" & hora & ";" & open & ";" & high & ";" & low & ";" & close & ";" & volume & ";" & interest
arq_destino.WriteLine(linhaescrever)
linhaAtual = arq_origem.ReadLine()
End While

End Sub
 
it seams that is something to do with the file im using. i tried with other file and worked. do you figure out whats going on ?

content of the file that worked:
line 1
line 2

content of the file that is not working:
<TICKER>,<NAME>,<PER>,<DATE>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>,<OPENINT>
TGMA3,TEGMA ON,D,20070703,000000,20.14018,20.83202,20.14018,20.37079,2538500,3722

the second line returns empty !
 
I could be wrong, but isn't readline() dependant on a CR+LF to denote the end of the line? My bet would be that the offending file doesn't have them... check in a text editor with a hex view.

Of course I could be wrong ;)
 
i really can't figure out whats wrong. both files have the same logic. but the second one does not work !!!! it's driving me nuts...
 
content of the file that is not working:
<TICKER>,<NAME>,<PER>,<DATE>,<TIME>,<OPEN>,<HIGH>, <LOW>,<CLOSE>,<VOL>,<OPENINT>
TGMA3,TEGMA ON,D,20070703,000000,20.14018,20.83202,20.14018,20 .37079,2538500,3722
Upload the sample text file that doesn't work as attachment to a post.
 
hi folks, other thing.
i found out that if i, manually, make a CR on the first line, it works. that is, the program that generates it is putting some character in the end of line that VB is not recognizing as a CR as menthos said... but the problem is, i cant change it because its third part software, and i must discover which char ends the lines and how to make vb understands it. any idea ? the original file is in this link ABCB4.txt - 4shared.com - document sharing - download
 
Thought so. I've seen this problem caused by the way a file gets to you - are you getting this file from an FTP site? If you are then the binary setting when transferring a file can impact line terminators (can't recall whether it needs to be set or unset)

There has to be something going on that's dropping those terminators.
 
no. there is a .exe that generates this files for me. its not via ftp. its locally. but i cant interfere in that procedure. i have to find out what terminators are those and how VB can recognize them. any idea ?
 
John, i think that is not the point. as you can see the lines are terminated with a "?" and by somehow VB understands that there is no more lines. the problem i think is to readlines terminated with "?" isn't it ?
 
you can see the lines are terminated with a "?"
No, they are not, see previous post.
 
John, i think that is not the point. as you can see the lines are terminated with a "?" and by somehow VB understands that there is no more lines. the problem i think is to readlines terminated with "?" isn't it ?

Each line is terminated by CR-CR-LF like JohnH said.

I'd recommend something better than Notepad to check out the files. Notepad++ is my editor of choice. It will actually show the extra blank line when you open the file.

You can show all the symbols in the document with Notepad++ by choosing View --> Show Symbol --> Show All Characters.
 
Back
Top