Hello Erika,
I have attempt your import - demo to adapt to an A comma/quote delimited file where the DATA VALUES are separated by A comma and each VALUE is enclosed in quotes. however so far without success. Please tell me where still errors in this code.
Thanks.
ASCII - file: "378280","1","76","5","28","6","20","20","24","24","43","43","1.01",".01","0.89"
"378281","1","77","5","13","6","27","27","16","16","40","40","0.35",".35","0.97"
"378282","2","21","5","50","6","45","45","117","117","29","29","23.8","3.8","118 " "373472","13","0.87","21","84","23","204","204","66","66","0.3","0.3","","","" "373473","1","94","5","29","6","20","20","16","16","0.83",".83","","",""
#include "sbasic_include.sbas"
var vCRS as Int // Child Result Set var vFile as Int // Results file var vPatient as String // Current PatientNo var vOrder as String // Current OrderNo var vLine as String // Current Results line from file var vVal as String // Current value from Results line var vLen as Int // Length of Results file var vTemp as Int var vDelimiter as String
FUNCTION ProcessLine() as Int var vRet as Int var vCode as String var vResult as String var vDelimiter as String
vDelimiter = @Chr(34) + "," + @Chr(34) vRet = 0 // Everything left in line should be code/result pairs. // Make a subrecord for each pair. While @Len(vLine) > 0 { vCode = Split(vLine, vDelimiter) vResult = Split(vLine, vDelimiter)
vCode = @Replfir(vCode, @Chr(34), "") vCode = @Repllas(vCode, @Chr(34), "") vResult = @Replfir(vResult, @Chr(34), "") vResult = @Repllas(vResult, @Chr(34), "") writeln("Hier ist Code: " + vCode + @NL() + "Hier das Resultat :" + vResult)
If (vCode <> "") And (vResult <> "") { // Make new chid record XResultSetCreateNewRecord(vCRS) XResultSetValue(vCRS, "PatientNo", vPatient) XResultSetValue(vCRS, "OrderNo", vOrder) XResultSetValue(vCRS, "ItemCode", vCode) XResultSetValue(vCRS, "UniqueCode", vOrder + vCode) XResultSetValue(vCRS, "DateAndResults", @Str(@ServerDate()) + " " + vResult) } Else { // If info not paired, abandon the line with error vRet = 1 } } Return vRet
END FUNCTION // Create an empty child record result set by specifying crtieria that no record will match vCRS = @XResultSetSearch(@FN, "Orders!Results", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!OrderNo==") If vCRS > -1 { vDelimiter = @Chr(34) + "," + @Chr(34) vFile = FileOpen("amor.txt") If vFile > -1 { FileSeek(vFile, 0) vLen = FileSize(vFile)
// Read and process results file line by line While (FilePos(vFile) < vLen) { vOrder = "" vPatient = "" FileReadLn(vFile, vLine) vLine = @Replfir(vLine, @Chr(34), "") vLine = @Repllas(vLine, @Chr(34), "") If @Len(vLine) > 0 { // Throw away first two values on line //vVal = Split(vLine, Tab(1)) //vVal = Split(vLine, Tab(1))
// Get OrderNo from Position 1 vVal = Split(vLine, vDelimiter) vVal = @Replfir(vVal, @Chr(34), "") vVal = @Repllas(vVal, @Chr(34), "")
If @Len(vVal) > 0 { vOrder = vVal
// Get matching PatientNo and confirm OrderNo exists vPatient = @XLookup(@FN, vOrder, "Orders!OrderNo", "PatientNo") vPatient = @Replfir(vVal, @Chr(34), "") vPatient = @Repllas(vVal, @Chr(34), "")
If @Len(vPatient) > 0 { // Process rest of line into subrecords vTemp = ProcessLine() If vTemp <> 0 { WriteLn("Error while processing Order: " + vOrder) } } Else { WriteLn("No matching Order record for: " + vOrder) } } } }
FileClose(vFile) } Else { @MsgBox("Error: Failed to open results file.", "", "") } XResultSetClose(vCRS) } Else { @MsgBox("Error: Failed to open child result set.", "", "") }
|