Help with import command

Brian K. White bw.aljex at gmail.com
Fri Apr 23 12:43:41 PDT 2021


Your import line and your file contents do not jive with each other. 
What's really going on?
f=& suggests this is really http form POST or possibly GET (query 
string) data, but there are no "&" delimiters in your sample data.
And r== makes no sense to me in this case.

If the data really does look like this, then you probably want to import 
as one big line, or use readline() not even import, and use instr() or 
maybe better strtok() to get the key & value parts using mid().
This way, the record separator is linefeed and ignores everything else, 
and never gets out of sync unless you have linefeeds within the data, 
and strtok() will get you that 1st "=" reliably, and if the value part 
contains any more ='s in it, no problem, they are just data from 
strtok() to newline.

Something like, this is not copied out of an actual process, so it may 
not work verbatim first try, but, like this.

if:
then: filename = "/path/to/file"
if:
then: filehandle = open(filename,"rt")
if: filehandle < "0"  ' could not open file
then: errorbox "bad file" ;goto done
if:
then: eof = seek(filehandle,"0","2") ' find end-of-file
if:
then: x = seek(filehandle,"0","0") ;cp = "1" ' return to start of file

readlin:
if cp >= eof   ' reached end-of-file
then: goto done
if:
then: reclen = readline(filehandle,data)
if:
then: delim = strtok(data,"=")
if: delim le "1"  ' invalid line, no "=" or no key before "="
then: goto "readlin"  ' skip this line
if:
then: key = mid(data,"1",delim) ; value = mid(data,delim+"1",reclen)
if:
then: ' *** do stuff with "key" and "value"
if:
then: goto "readlin" ' get next line of data

done: ' clean up & end
if: filehandle > "0"
then: x = close(filehandle)
if:
then: ' maybe x - remove(filename)
if:
then: exit  ' or return, or end, whatever depending on context.

If the data is actually more messy than what you showed, then this isn't 
enough.

-- 
bkw


On 4/23/21 11:11 AM, Richard Kreiss via Filepro-list wrote:
> Below is the file I am trying to import:
>
> response=1
> responsetext=SUCCESS
> authcode=123456
> transactionid=6174664263
> avsresponse=
> cvvresponse=M
> orderid=
> type=sale
> response_code=100
>
> The import processing:
>        ◄ If:
>        Then: import ASCII field=(ifile) o=& c== r== f=&
> 17  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If:         NOT field
>        Then:         ERRORBOX "(17) Done reading the file\nThe counter Ct is at
> 18  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If:
>        Then:         ct=ct+"1"
> 19  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If:
>        Then:         im=field(1)
> 20  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If:         IM CO CHR("124")
>        Then:         gosub RMV_124;goto DO_FIEL
> 21  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If:         CT LT "20"
>        Then: goto DO_FIEL
> 22  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
> do_fiel◄ If: '*****************************************************************
>        Then: '* routine to set fierld values
> 23  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If: ct = "1" or ct = "5" or ct = "7" or ct= "9" or ct = "12" or ct = "
>        Then: MSGBOX "The Value of im is \b5"<im<"\nThe counter is at \b6"<ct<"\
> 24  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If: im="response"        'loop back to get the value of the "response"
>        Then: il=im;im="";GOTO get_Imp   'whici is usually a single digit number
> 25  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If: il="Response"                 'value of response in in field
>        Then: fields["1"]=im;il="";im="";GOTO get_imp   'im usually a single num
> 26  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If: im="Success"
>        Then: fields["2"]=im;il="";im="";GOTO get_imp   'im usually a single num
> 27  -------   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
>        ◄ If: 'im ="responsetext"
>        Then: 'il=im;CT="3";goto GET_Imp
>
> Problem is tht the import works properly foe the first two imports but then skips the the value to the left of the equal = sign.
>
> The first import is response (correct) and the second is 1.  The issue I am having is that the next value imported is Success and not Responsetext. This is happening with each import, the value to expected is not the “header” but the value of the header.(the value to the right of the equal sign =).
>
> Does anyone have an answer as to why I am having this problem and how for fix it?
>
>
> Richard Kreiss
> GCC Consulting
>
>
>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: winmail.dat
> Type: application/ms-tnef
> Size: 19645 bytes
> Desc: not available
> URL: <http://mailman.celestial.com/pipermail/filepro-list/attachments/20210423/734166c7/attachment.bin>
> _______________________________________________
> Filepro-list mailing list
> Filepro-list at lists.celestial.com
> Subscribe/Unsubscribe/Subscription Changes
> http://mailman.celestial.com/mailman/listinfo/filepro-list



More information about the Filepro-list mailing list