Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Oct 21, 2019 11:02 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Little problem with text file inport.
PostPosted: Fri Jan 18, 2013 6:28 pm 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
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
 Profile  
Reply with quote  
 Post subject: Re: Little problem with text file inport.
PostPosted: Fri Jan 18, 2013 6:55 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
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
 Profile  
Reply with quote  
 Post subject: Re: Little problem with text file inport.
PostPosted: Fri Jan 18, 2013 8:04 pm 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
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
 Profile  
Reply with quote  
 Post subject: Re: Little problem with text file inport. (Solved)
PostPosted: Fri Jan 18, 2013 8:32 pm 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
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
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group