Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Append From command craziness
Message
From
18/11/2002 13:38:33
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
18/11/2002 00:13:44
Jordan Pastourel
Worksafe Management Systems
Toowong, Australia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00723745
Message ID:
00723952
Views:
16
>Hi all,
>i am having a bit of a problem with the Append From command. Here is the issue:
>i create a cursor to match the format of a .csv file (field delimited by , and character delimited by ")
>
>i then use the append from command to put the data into a foxpro table:
>append from &fileclaim delimited
>
>all seemed to go well for a while until i realised that within some of the character fields there were statements like "there was a 6" gap". with the " after the 6 "gap" moves onto the next field and stuffs up all the rest of the record with the fields all moved along one.

Doable - been there, done that. First, get the whole file into a string:
lcText=filetostr(fileclaim)
Now if all your data are strings, delimited by quotes, it's easier, but if you also got numbers, it'll be a little nastier:
lcText=lf+strtran(lcText, [",], [^,])+cr
* this was to fake crlf characters for first and last line, though the last line probably has one already
lcText=strtran(lcText, [,"], [,^])
lcText=strtran(lcText, ["]+cr, [^]+cr)  && last quote at the end of line
lcText=strtran(lcText, lf+["], lf+[^])  && the ones at beginning of line
* now we got all the separating quotes replaced with carons:
strtofile(subs(lcText,2,len(lcText)-1), FileClaim)
append from (FileClaim) type delimited with "^"  && not sure of exact syntax here
If you don't get the exact syntax for appending from the caron delimited and comma separated file, you can always do this before the StrToFile():
lcText=chrtran(lcText,["^], [^"])
i.e. just swap them, and then later swap back in the fields in the table where you got carons. In this case you'd have a file with quotes for delimiters, and only the in-string quotes would be replaced with carons.
(and don't use & for filenames, it breaks badly if filename contains a space)

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform