JP_Goblet
asked on
import a text file with ADO : problem with delimiters
i import text files wherein delimiter is space; these can be several spaces between each data item; for example
Code No X Y Z Zval Dh Couche
Station pnt2 -357.507 12.740 0.000 !! 0.000 CourbesNiveau
Station pnt1 -394.368 55.635 0.000 !! 0.000 CourbesNiveau
the ado driver process a string of spaces as mutiple delimiters (with NULL data between), so i get garbage;
is it possible to process a string of spaces as a single delimiter ?
Code No X Y Z Zval Dh Couche
Station pnt2 -357.507 12.740 0.000 !! 0.000 CourbesNiveau
Station pnt1 -394.368 55.635 0.000 !! 0.000 CourbesNiveau
the ado driver process a string of spaces as mutiple delimiters (with NULL data between), so i get garbage;
is it possible to process a string of spaces as a single delimiter ?
What is being used as the Delimiter in the text file? Is this a tab-delimited file, a comma-delimited file, etc etc? I've never had much luck using ADO to import files, unless they were files my code built (and I could control how it was built, of course) ...
ASKER
as said in my 1st post, the delimiter is space; but in fact it can be any other character, i just have to record in the registry the delimiter i use before import; for example :
RegOpenKeyEx(HKEY_LOCAL_MA CHINE, "SOFTWARE\\Microsoft\\Jet\ \4.0\\Engi nes\\Text" ,
0, KEY_QUERY_VALUE|KEY_SET_VA LUE, &hkey);
retval = RegSetValueEx(hkey, "Format", NULL, REG_SZ, "Delimited( )", 20);
RegCloseKey(hkey);
the import works well if the text file contain only one delimiter between 2 data items (aa bb cc ...);
but it fails if several delimiters are used between data items (aa bb cc ...)
RegOpenKeyEx(HKEY_LOCAL_MA
0, KEY_QUERY_VALUE|KEY_SET_VA
retval = RegSetValueEx(hkey, "Format", NULL, REG_SZ, "Delimited( )", 20);
RegCloseKey(hkey);
the import works well if the text file contain only one delimiter between 2 data items (aa bb cc ...);
but it fails if several delimiters are used between data items (aa bb cc ...)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i have no control on the format of the input file, it's a file made by the user (which explains such 'anomalies' as mutiple delimiters), i just have to import it ...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
stevbe --> fix up the file before import : i thought about it, but if i have to do it, then i doesn't cost much more to import at the same time by parsing each line (it means i don't use ado anymore)
idfke --> i program in visual c++ 6.0, so i dont' have access to such objects as RegExp
anyway, thank you all for your comments (i will split the points), but i've decided to leave ado and do the import by reading the text line by line and parsing each line.
Anyway ado has others limitations : the files i import can use different delimiters at the same time (for example spaces & tabulations), so again ado couldn't import it directly, a preprocessing would be needed. Other limitation : if the data fields in the file are of fixed lenghs, ado needs an auxiliary file (schema.ini) to set the field lengths, and that file has to be in the same directory than the imported file : a very severe (stupid ?) limitation : how do i import a file from a cd or from a read-only directory ?
The only thing i will miss from ado is the possibility to filter with a sql query (select ... where Result = "OK").
I'm writing now a class CTxtRecordSet that will emulate a recordset : MoveFirst, MoveNext, GetFieldValue, ...
idfke --> i program in visual c++ 6.0, so i dont' have access to such objects as RegExp
anyway, thank you all for your comments (i will split the points), but i've decided to leave ado and do the import by reading the text line by line and parsing each line.
Anyway ado has others limitations : the files i import can use different delimiters at the same time (for example spaces & tabulations), so again ado couldn't import it directly, a preprocessing would be needed. Other limitation : if the data fields in the file are of fixed lenghs, ado needs an auxiliary file (schema.ini) to set the field lengths, and that file has to be in the same directory than the imported file : a very severe (stupid ?) limitation : how do i import a file from a cd or from a read-only directory ?
The only thing i will miss from ado is the possibility to filter with a sql query (select ... where Result = "OK").
I'm writing now a class CTxtRecordSet that will emulate a recordset : MoveFirst, MoveNext, GetFieldValue, ...
Thanks !
;-)
;-)