Normal Topic Suggestions for parsing a file (Very long read) (Read 1082 times)
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Suggestions for parsing a file (Very long read)
Oct 1st, 2012 at 4:47pm
Print Post Print Post  
Sorry for writing a novel  I am just attempting to be clear.

In our application we have been passing information to the UPS shipping system as part of the Sbasic commands when a user processes and posts serial number info for a specific record.

This saves the need to re-enter data to UPS, speeds up shipping, helps stop errors caused when typing data a second time  and passes additional information to be printed on the UPS labels such as correct serial numbers and special handling needs that would not be seen if a shipper was doing this without sesame.

Sesame does such an excellent job communicating with UPS Worldship we are now wanting to pass information such as delivery tracking number, return tag tracking number , estimated delivery time etc.. back to the record once shipped.

What I have now is:
the shipper shoots a barcode on a piece of equipment  from Sesame
This automaticaly  starts a retrieve and brings up the record and pops up an askuser  box
The shipper shoots a barcode on a picking ticket and it closes the askuser box and grabs data from a lookup,
Sesame creates a subrecord in the equipment database (so it has its own history of where, when and whom it went)
posts the serial number,  shipping date and a few other bits of data to the patient record
and passes the shipping details to UPS.

The Ups system then spits out a shipping label and a return tag label and writes the shipping information (tracking number, estimated delivery time etc..) to an existing file on a shared server.

I am now wanting to grab some of the information from that file and post it back to the record I am in.

I would love some suggestions on the best method to read and parse that file.

What I have been trying so far is:
I have set UPS Worldship to write the info to the file with semi colons as a separator so when I read it in I read it as a string array.
I have been using @insert and am able to properly set the string array so I have 35 strings per shipping event.

I now need to figure out how best to search the specific strings and grab the specific info I need. I have been trying searchString array but I am not sure if I should read all the records and create a new record in a new new database and then lookup what  info I want or how to progress.  I am not even sure if converting to a string array is a good way to go. I am stuck and could use some advice.

I think I may be over complicating this, so please suggest other thoughts, methods, ideas that will get me going in the correct direction.

Thanks so much.
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Suggestions for parsing a file (Very long read)
Reply #1 - Oct 1st, 2012 at 5:35pm
Print Post Print Post  
Having the record data as a string array is a great way to access the data in it but first we have to get the record that we want. The best way would be to have the first few pieces of data on each line in the file be unique information that Sesame has so the programming can see which line to pick up. Not sure if you can set the order of the fields that are exported by UPS or not.

If the first part of the line has unique data in it I would probably use @Insert to insert the whole file, use SetStringArraySeparator() to set the separator to @Newline(), then @SearchStringArray() on the string that is the file contents to pick up just the line that we want. Once we have that line, RestoreArraySeparator() and use @AccessStringArray() to pull the data out of it that we need.

-Ray


-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Suggestions for parsing a file (Very long read)
Reply #2 - Oct 1st, 2012 at 5:56pm
Print Post Print Post  
Ray thanks for the input.

The code below is the way I have been slowly stepping through the file to figure things out.

V1 is the unique patient id. However there are 2 records with this id because 1 is the shipping info the second is the return tag info

V25 tells me if it is the outbound record or return tag record

V29 is the tracking number I want to grab for the shipping or return tag.

As you will see I was trying @SearchStringArray(vContent, "201209281526") to get to the right place but was floundering where or how I should  be using that.

Thanks again


var vFile as String
var vContent as String
var vLine as String
var n as Int
var nn as Int
var v1 as String
var v2 as String
var v3 as String
var v4 as String
var v5 as String
var v6 as String
var v7 as String
var v8 as String
var v9 as String
var v10 as String
var v11 as String
var v12 as String
var v13 as String
var v14 as String
var v15 as String
var v16 as String
var v17 as String
var v18 as String
var v19 as String
var V20 as String
var v21 as String
var v22 as String
var v23 as String
var v24 as String
var v25 as String
var v26 as String
var v27 as String
var v28 as String
var v29 as String
var v30 as String
var v31 as String
var v32 as String
var v33 as String
var v34 as String
var v35 as String
var v36 as String
var v37 as String
var v38 as String
var v39 as String

//"201209281526" unique patient Id to test with

var vsearched as String
var vBlank1 as String

vFile  = "c:\sesame\UPSEXPTrak.csv"

//vBlank1 = blank1



vContent = @Insert(vFile)
SetStringArraySeparator(@NewLine())
vContent = @SortStringArray(vContent, 0)




For n = 1 to @CountStringArray(vContent)
vLine = @AccessStringArray(vContent, n)
SetStringArraySeparator(";")
//nn = @CreateNewRecord()
v1 = @AccessStringArray(vLine, 1)
v2 = @AccessStringArray(vLine, 2)
v3 = @AccessStringArray(vLine, 3)
v4 = @AccessStringArray(vLine, 4)
v5 = @AccessStringArray(vLine, 5)
v6 = @AccessStringArray(vLine, 6)
v7 = @AccessStringArray(vLine, 7)
v8 = @AccessStringArray(vLine, 8)
v9 = @AccessStringArray(vLine, 9)
v10 = @AccessStringArray(vLine, 10)
v11 = @AccessStringArray(vLine, 11)
v12 = @AccessStringArray(vLine, 12)
v13 = @AccessStringArray(vLine, 13)
v14 = @AccessStringArray(vLine, 14)
v15 = @AccessStringArray(vLine, 15)
v16 = @AccessStringArray(vLine, 16)
v17 = @AccessStringArray(vLine, 17)
v18 = @AccessStringArray(vLine, 18)
v19 = @AccessStringArray(vLine, 19)
v20 = @AccessStringArray(vLine, 20)
v21 = @AccessStringArray(vLine, 21)
v22 = @AccessStringArray(vLine, 22)
v23 = @AccessStringArray(vLine, 23)
v24 = @AccessStringArray(vLine, 24)
v25 = @AccessStringArray(vLine, 25)
v26 = @AccessStringArray(vLine, 26)
v27 = @AccessStringArray(vLine, 27)
v28 = @AccessStringArray(vLine, 28)
v29 = @AccessStringArray(vLine, 29)
v30 = @AccessStringArray(vLine, 30)
v31 = @AccessStringArray(vLine, 31)
v32 = @AccessStringArray(vLine, 32)
v33 = @AccessStringArray(vLine, 33)
v34 = @AccessStringArray(vLine, 34)
v35 = @AccessStringArray(vLine, 35)





     //vsearched  = @SearchStringArray(str1, "vBlank1")

writeln("search = " + vBlank1)

     //vBlank1 = @SearchStringArray(vContent, "201209281526")
//writeln("search = " + vBlank1)


writeln("1   " + v1)
writeln("2   " + v2)
writeln("3   " + v3)
writeln("4   " + v4)


writeln("5   " + v5)
writeln("6  " + v6)
writeln("7   " + v7)
writeln("8   " + v8)
writeln("9   " + v9)
writeln("1   " + v10)
writeln("11   " + v11)
writeln("12   " + v12)
writeln("13   " + v13)
writeln("14   " + v14)
writeln("15   " + v15)
writeln("16   " + v16)
writeln("17   " + v17)
writeln("18   " + v18)
writeln("19   " + v19)


writeln("20   " + v20)
writeln("21   " + v21)
writeln("22   " + v22)
writeln("23  " + v23)
writeln("24   " + v24)

writeln("25   " + v25)
writeln("26   " + v26)
writeln("27   " + v27)
writeln("28   " + v28)
writeln("29  " + v29)
writeln("30   " + v30)
writeln("31   " + v31)
writeln("32   " + v32)
writeln("33  " + v33)
writeln("34  " + v34)
writeln("35  " + v35)
//writeln(v36)
//writeln(v37)
//writeln(v38)
//writeln(v39)




RestoreStringArraySeparator()
Next
RestoreStringArraySeparator()

  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Suggestions for parsing a file (Very long read)
Reply #3 - Oct 1st, 2012 at 9:04pm
Print Post Print Post  
Hey Robert,

Something like the following should work for you. "return tag" will need to be whatever value marks that record as the return record.

Code
Select All
var vFile as String
var vContent as String
var vLine as String
var n as Int
var nn as Int

//"201209281526" unique patient Id to test with

var vsearched as String
var vBlank1 as String

vFile  = "c:\sesame\UPSEXPTrak.csv"

//vBlank1 = blank1



	vContent = @Insert(vFile)
	SetStringArraySeparator(@NewLine())
	vContent = @SortStringArray(vContent, 0)
	vContent = @SearchStringArray(vContent, "201209281526..")
	RestoreStringArraySeparator()
	If vContent <> "" Then
	{
		While vContent <> ""
		{
			vLine = Split(vContent, @Newline())
			If @AccessStringArray(vLine, 25) = "return tag"
			{
				TrackingNumber = @AccessStringArray(vLine, 29)
			}
		}
	}
 

  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Suggestions for parsing a file (Very long read)
Reply #4 - Oct 1st, 2012 at 11:43pm
Print Post Print Post  
Ray,

as always you are an incredible help. Your code has got me on the correct track.

As you will see below I cobbled up your nice tight code so I could walk through it slowly and really understand what was working and what was not.

The first thing I realized was that I had the file from UPS in the wrong format, once I corrected that my search string array worked well.

Next problem I had was it found the line but it did not properly turn it into a string. Once I corrected my SetStringArraySeparator(",") that worked to seperate the data.

Now I have 2 records it finds. I attempted to use an if statement to decide what data was what and return it properly but I always get the last record data only.

I am now thinking I should rebuild the string to make a separate unique ID for each one of the 2 data strings its finding and then do another search to break it down farther.

I am getting closer thanks to your help.

Thanks again for the help
///

var v1 as String
var v2 as String
var v3 as String
var v4 as String
var v5 as String
var v6 as String
var v7 as String
var v8 as String
var v9 as String
var v10 as String
var v11 as String
var v12 as String
var v13 as String
var v14 as String
var v15 as String
var v16 as String
var v17 as String
var v18 as String
var v19 as String



var V20 as String
var v21 as String
var v22 as String
var v23 as String
var v24 as String
var v25 as String
var v26 as String
var v27 as String
var v28 as String
var v29 as String
var v30 as String
var v31 as String
var v32 as String
var v33 as String
var v34 as String
var v35 as String
var v36 as String
var v37 as String
var v38 as String
var v39 as String

var vtrak as String
var vreturn as String



var vFile as String
var vContent as String
var vLine as String
var n as Int
var nn as Int

//"201209281526" unique patient Id to test with

var vsearched as String
var vBlank1 as String

vFile  = "c:\sesame\UPSEXPTrak.csv"
//vFile  = "c:\sesame\UPSADDRESSBOOK.csv"

//Writeln(vfile)
//vBlank1 = blank1



     vContent = @Insert(vFile)


//Writeln("start  " + vContent)

     //vcontent = @Replace(vcontent, ";",  "")

     //Writeln("replace  " + vContent)

     SetStringArraySeparator(@NewLine())

     vContent = @SortStringArray(vContent, 0)


//Writeln("after sort  " + vContent)

     vContent = @SearchStringArray(vContent, "201209281526..")
     //vContent = @SearchStringArray(vContent, "20120430845..")

//Writeln("after search  " + vContent)

     RestoreStringArraySeparator()
     If vContent <> "" Then
     {
           While vContent <> ""
           {
                 vLine = Split(vContent, @Newline())

Writeln("this is vline  " + vline)

Writeln("after vline***********************************************")


     SetStringArraySeparator(",")

     //vline = @SortStringArray(vline, 0)

v1 = @AccessStringArray(vLine, 1)
v2 = @AccessStringArray(vLine, 2)
v3 = @AccessStringArray(vLine, 3)
v4 = @AccessStringArray(vLine, 4)
v5 = @AccessStringArray(vLine, 5)
v6 = @AccessStringArray(vLine, 6)
v7 = @AccessStringArray(vLine, 7)
v8 = @AccessStringArray(vLine, 8)
v9 = @AccessStringArray(vLine, 9)
v10 = @AccessStringArray(vLine, 10)
v11 = @AccessStringArray(vLine, 11)
v12 = @AccessStringArray(vLine, 12)
v13 = @AccessStringArray(vLine, 13)
v14 = @AccessStringArray(vLine, 14)
v15 = @AccessStringArray(vLine, 15)
v16 = @AccessStringArray(vLine, 16)
v17 = @AccessStringArray(vLine, 17)
v18 = @AccessStringArray(vLine, 18)
v19 = @AccessStringArray(vLine, 19)
v20 = @AccessStringArray(vLine, 20)
v21 = @AccessStringArray(vLine, 21)
v22 = @AccessStringArray(vLine, 22)
v23 = @AccessStringArray(vLine, 23)
v24 = @AccessStringArray(vLine, 24)
v25 = @AccessStringArray(vLine, 25)
v26 = @AccessStringArray(vLine, 26)
v27 = @AccessStringArray(vLine, 27)
v28 = @AccessStringArray(vLine, 28)
v29 = @AccessStringArray(vLine, 29)
v30 = @AccessStringArray(vLine, 30)
v31 = @AccessStringArray(vLine, 31)
v32 = @AccessStringArray(vLine, 32)
v33 = @AccessStringArray(vLine, 33)
v34 = @AccessStringArray(vLine, 34)
v35 = @AccessStringArray(vLine, 35)



writeln("1   " + v1)
writeln("2   " + v2)
writeln("3   " + v3)
writeln("4   " + v4)


writeln("5   " + v5)
writeln("6  " + v6)
writeln("7   " + v7)
writeln("8   " + v8)
writeln("9   " + v9)
writeln("1   " + v10)
writeln("11   " + v11)
writeln("12   " + v12)
writeln("13   " + v13)
writeln("14   " + v14)
writeln("15   " + v15)
writeln("16   " + v16)
writeln("17   " + v17)
writeln("18   " + v18)
writeln("19   " + v19)


writeln("20   " + v20)
writeln("21   " + v21)
writeln("22   " + v22)
writeln("23  " + v23)
writeln("24   " + v24)

writeln("25   " + v25)
writeln("26   " + v26)
writeln("27   " + v27)
writeln("28   " + v28)
writeln("29  " + v29)
writeln("30   " + v30)
writeln("31   " + v31)
writeln("32   " + v32)
writeln("33  " + v33)
writeln("34  " + v34)
writeln("35  " + v35)

                 //If @AccessStringArray(vLine, 25) <> "UPS Print Return Label"
                 If v25 = "UPS Print Return Label"

                 {
                       
                       vreturn = v29
                       Writeln("this is return   " + vtrak)

//TrackingNumber = @AccessStringArray(vLine, 29)
                       //Writeln("this is it   " + @AccessStringArray(vLine, 29))


                 }



                 //If @AccessStringArray(vLine, 25) = ""
                 If v25 = ""
                 {
                       
                       vtrak = v29
                       Writeln("this is traking   " + vtrak)
//TrackingNumber = @AccessStringArray(vLine, 29)
                       //Writeln("this is it   " + @AccessStringArray(vLine, 29))


                 }



           }
     }



  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Suggestions for parsing a file (Very long read)
Reply #5 - Oct 1st, 2012 at 11:47pm
Print Post Print Post  

Using Regex is an excellent way to parse out desired strings from most text type of files.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Suggestions for parsing a file (Very long read)
Reply #6 - Oct 2nd, 2012 at 2:57pm
Print Post Print Post  
Bob  great Idea, regex is a great tool however I decided to take a very simple (maybe lazy way) to solve the problem.

Since  my search @SearchStringArray  would find 2 records because the same Id has 1 for the shipping label and 1 for the return label I just decided to run the search return through @replace

vContent = @replace(vContent, @chr(10), ",")

This eliminated the line feed and made the 2 records look like 1. I then split the data turning it back into a bigger string array and my tracking number ended up in 1 string and my return in another.

Thanks everyone for the help. I could not have figured this out without the help.
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged