New topic: Little problem with text file inport.
<http://forums.realsoftware.com/viewtopic.php?t=46611> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message Antonio Post subject: Little problem with text file inport.Posted: Fri Jan 18, 2013 6:28 pm Joined: Sat Feb 04, 2012 1:26 pm Posts: 76 Location: Italy Hi, 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 f=GetOpenFolderItem("text") IF blnResult = TRUE THEN If f <> Nil then t=TextInputStream.Open(f) t.Encoding=Encodings.MacRoman 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) wend DB.Commit DB.Close t.Close End if else MsgBox "Database Error: " + str(DB.ErrorCode) + EndOfLine + DB.ErrorMessage end if thanks for helping, Antonio Top ktekinay Post subject: Re: Little problem with text file inport.Posted: Fri Jan 18, 2013 6:55 pm Joined: Mon Feb 05, 2007 5:21 pm Posts: 374 Location: New York, NY 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: t=TextInputStream.Open(f) t.Encoding=Encodings.MacRoman 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 ) exit end if ... BTW, with a single-byte encoding like MacRoman, the "B" version of the string functions will be faster. _________________ Kem Tekinay MacTechnologies Consulting http://www.mactechnologies.com/ Need to develop, test, and refine regular expressions? Try RegExRX. Top Antonio Post subject: Re: Little problem with text file inport.Posted: Fri Jan 18, 2013 8:04 pm Joined: Sat Feb 04, 2012 1:26 pm Posts: 76 Location: Italy Kem, 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. Top Antonio Post subject: Re: Little problem with text file inport. (Solved)Posted: Fri Jan 18, 2013 8:32 pm Joined: Sat Feb 04, 2012 1:26 pm Posts: 76 Location: Italy 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. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
