Page Index Toggle Pages: 1 [2]  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) [Solved] importing ASCII file in Subform (Read 2378 times)
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: [Solved] importing ASCII file in Subform
Reply #15 - Sep 26th, 2007 at 11:03am
Print Post Print Post  
Hello Erika!

I would like to thank you very much for snap and applicable example. It functioned excellent. I have today its App. example with the following tape tested however I get the following error message:
378206 KAL 75 NAT 29 PSA 19 CHL 18 NO matching order record for: 378206 KAL 75 NAT 29 PSA 19 CHL 18

The order record 378206 exists already in order form!
I believe it have with the tab problem.
I do not believe that Separator in these ASCII - File is a tabulator (only blanks as Separater!).
I have unfortunately no experience thereby!

Hier is the tested amor.txt file.

Thanks.
Dr.Belhareth
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: [Solved] importing ASCII file in Subform
Reply #16 - Sep 26th, 2007 at 11:06am
Print Post Print Post  
Amor,

Pasting into the Forum changes things like spaces. Can you email the test file to Support so we can see what you actually have?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: [Solved] importing ASCII file in Subform
Reply #17 - Sep 26th, 2007 at 1:34pm
Print Post Print Post  
Amor,

The file you sent does not appear to be a delimited file. It looks more like a fixed width file. The method to parse this is pretty much the same as I gave you, but you can't use Split. You would need to use @Mid instead to pull out each piece. In order to do this accurately, you will need the format specification for these files. This is a document that tells you exactly how many characters each piece of data is given. The people sending you these files would need to provide this to you.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: [Solved] importing ASCII file in Subform
Reply #18 - Sep 27th, 2007 at 2:34pm
Print Post Print Post  
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.", "", "")
     }

  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: [Solved] importing ASCII file in Subform
Reply #19 - Sep 27th, 2007 at 4:10pm
Print Post Print Post  
Amor,

I'm having trouble advising you here. Every time you post the ASCII file, it has a completely different format. Are you producing this file yourself or is it being given to you by someone else?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: [Solved] importing ASCII file in Subform
Reply #20 - Sep 27th, 2007 at 4:37pm
Print Post Print Post  
Hello Erika,

Because our 8 Analyser for various investigations of different companies. Unfortunately those do not have uniform output formats.

Dr. Belhareth
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: [Solved] importing ASCII file in Subform
Reply #21 - Sep 28th, 2007 at 3:00pm
Print Post Print Post  
Quote:
Hello Erika,

Because our 8 Analyser for various investigations of different companies. Unfortunately those do not have uniform output formats.


Ah. OK. Try something like below. I had it replace the "," with ^ so the parsing isn't so difficult and you don't have to keep stripping quotes. I also adjusted the logic in ProcessLine to allow both Code and Result to be blank without an error, since that seems to occur with this file. Although, none of the values in this file look like Codes to me. They all look like results. I can't really tell though...

Code
Select All
#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

	vRet = 0
	// Everything left in line should be code/result pairs.
	// Make a subrecord for each pair.
	While (@Len(vLine) > 0) And (vRet = 0)
	{
		vCode = Split(vLine, vDelimiter)
		vResult = Split(vLine, vDelimiter)

		If (vCode <> "") Or (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 = "^"
	     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), "")
			vLine = @Replace(vLine, @Chr(34) + "," + @Chr(34), "^")

			     If @Len(vLine) > 0
			     {
				    // Get OrderNo from Position 1
				     vVal = Split(vLine, vDelimiter)
				    If @Len(vVal) > 0
				     {
					     vOrder = vVal

					     // Get matching PatientNo and confirm OrderNo exists
				     	vPatient = @XLookup(@FN, vOrder, "Orders!OrderNo", "PatientNo")
					    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.", "", "")
     }
 

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send Topic Send Topic Print Print