Real Software Forums

Little problem with text file inport.
Page 1 of 1

Author:  Antonio [ Fri Jan 18, 2013 6:28 pm ]
Post subject:  Little problem with text file inport.

I have a plain text file containing about 45000 rows. Each row is 100 characters long and must be splitted in several fields. then I have to import thoses fields into a ms access table.

My code, seems, to work, but not exactly how it should. Infacts, it doesn't import all the 45000, but something less more 38000.

I don't know where I did the mistake.

this is the code to inport the file.

dim blnResult as Boolean
dim rs as new DatabaseRecord
blnResult = DB.Connect
dim data, leggelinea as String
Dim f As FolderItem
Dim t As TextInputStream

IF blnResult = TRUE THEN
If f <> Nil then


while not t.EOF
leggelinea = t.ReadLine
RS.Column("Item") = mid(leggelinea,1,4)
RS.Column("Code") = mid(leggelinea,5,12)
RS.column("Name") = mid(leggelinea,17,18)
RS.column("cat") = mid(leggelinea,35,2)
RS.column("weight") = mid(leggelinea,37,3)
RS.column("Rapporto") = mid(leggelinea,40,8)
data = mid(leggelinea,48,2) +"/"+ mid(leggelinea,50,2)+"/"+ mid(leggelinea,52,4)
RS.column("Data_in") = data
RS.column("Price1") = mid(leggelinea,56,8)
RS.column("Price2") = mid(leggelinea,64,8)
RS.column("Country") = mid(leggelinea,72,3)
RS.column("Phone") = mid(leggelinea,75,25)
DB.InsertRecord("Orders 2012", RS)

End if

MsgBox "Database Error: " + str(DB.ErrorCode) + EndOfLine + DB.ErrorMessage
end if

thanks for helping,

Author:  ktekinay [ Fri Jan 18, 2013 6:55 pm ]
Post subject:  Re: Little problem with text file inport.

I don't see anything wrong with your code, so perhaps it's in your data. Try adding these lines and see what you get:

dim lineIndex as integer
while not t.EOF
lineIndex = lineIndex + 1
leggelinea = t.ReadLine
if leggelinea.Len <> 100 then
MsgBox "Problem with data at line " + str( lineIndex )
end if

BTW, with a single-byte encoding like MacRoman, the "B" version of the string functions will be faster.

Author:  Antonio [ Fri Jan 18, 2013 8:04 pm ]
Post subject:  Re: Little problem with text file inport.


it says there is a problem at line number 43220.
I used str(leggelinea.len) to get the lenght and it ruturns 2.
anyway i saw that 43220 is the first blank line.
there are no more lines after that. the files contains exactly 43219
opening the file into Excel.

Author:  Antonio [ Fri Jan 18, 2013 8:32 pm ]
Post subject:  Re: Little problem with text file inport. (Solved)

Think I solved the issue.
I think the problem arise not in reading the line, but in storing it into the db.
that should happend because some of the lines, eventhouth they are the right lenght, do not contain fields compatible with the db. for exemple in the db currency type field, it might try to store a "????????" satring where thhat stands for and empty record.
So at the end, as you suggested, there was something wrong with the file.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group