Help Anyone (who has experience processing Long Ascii Strings) 
Author Message
 Help Anyone (who has experience processing Long Ascii Strings)

First of all, I'm new to Foxpro and also I'm using Version 3.0a.

I have to process long strings wwhic ar exported from my (Realworld)
Accounting program.

What I woudl liek to do is to have a program simply read the entire string -
just as it comes in the (exported) ASCII file, and process each line, and
parse into fields which I can then access, etc.

One problem which I have is that the numeric fields are exported as for eg
below:

                                               ..........   000001234560000+
.............
                                               ..........   000005678940000-
..............
note that the first is a positive figure and thesecond a negative.

Now, when I use the Import wizard, (which I am reluctant to do since I, as I
said above, ideally I would like to have a program read the exported file as
is), and read this into a numeric field (created  previously) I find I am
not getting the correct results.

I also have a similar problem with date field which are exported as:

                                                    ............ 980910
..............

I suppose the answer to the above is some long  routine to check each
character individually etc etc!

Any suggestions?

Thanks in advance!



Wed, 28 Feb 2001 03:00:00 GMT  
 Help Anyone (who has experience processing Long Ascii Strings)
Try exporting and then appending record by record into another file.

Via substr()...format conversion and etc field by field replace techniques....

                                  <Dragon Reigns>



Wed, 28 Feb 2001 03:00:00 GMT  
 Help Anyone (who has experience processing Long Ascii Strings)

Quote:

> First of all, I'm new to Foxpro and also I'm using Version 3.0a.

> I have to process long strings wwhic ar exported from my (Realworld)
> Accounting program.

> What I woudl liek to do is to have a program simply read the entire string -
> just as it comes in the (exported) ASCII file, and process each line, and
> parse into fields which I can then access, etc.

> One problem which I have is that the numeric fields are exported as for eg
> below:

>                                                ..........   000001234560000+
> .............
>                                                ..........   000005678940000-
> ..............
> note that the first is a positive figure and thesecond a negative.

> Now, when I use the Import wizard, (which I am reluctant to do since I, as I
> said above, ideally I would like to have a program read the exported file as
> is), and read this into a numeric field (created  previously) I find I am
> not getting the correct results.

> I also have a similar problem with date field which are exported as:

>                                                     ............ 980910
> ..............

> I suppose the answer to the above is some long  routine to check each
> character individually etc etc!

> Any suggestions?

> Thanks in advance!

If I have guessed correctly, your numbers are 11 digits with 4 decimal
places?

After you have separated all 'fields' as strings. For the number
(including the +/- sign):

m_num = VAL(LEFT(m_str,11) + (VAL(SUBSTR(m_str,12,4)/10000)

Then:

IF RIGHT(m_str,1) = "-"
  m_num = 0 - m_num
ENDIF

As to the date:

m_strdat =  SUBSTR(m_str,3,2) + "/" + RIGHT(m_str,2) + "/" +
LEFT(m_str,2)
m_dat = CTOD("&m_strdat")

HTH



Wed, 28 Feb 2001 03:00:00 GMT  
 Help Anyone (who has experience processing Long Ascii Strings)

Quote:

> First of all, I'm new to Foxpro and also I'm using Version 3.0a.

> I have to process long strings wwhic ar exported from my (Realworld)
> Accounting program.

> What I woudl liek to do is to have a program simply read the entire string -
> just as it comes in the (exported) ASCII file, and process each line, and
> parse into fields which I can then access, etc.

> One problem which I have is that the numeric fields are exported as for eg
> below:

>                                                ..........   000001234560000+
> .............
>                                                ..........   000005678940000-
> ..............
> note that the first is a positive figure and thesecond a negative.

> Now, when I use the Import wizard, (which I am reluctant to do since I, as I
> said above, ideally I would like to have a program read the exported file as
> is), and read this into a numeric field (created  previously) I find I am
> not getting the correct results.

> I also have a similar problem with date field which are exported as:

>                                                     ............ 980910
> ..............

> I suppose the answer to the above is some long  routine to check each
> character individually etc etc!

> Any suggestions?

It really isn't that difficult to use the low level call to read the
ACSII text files and parse the fields you know to be present. If you do
it once, you have a model for the next one that comes along.


Thu, 01 Mar 2001 03:00:00 GMT  
 Help Anyone (who has experience processing Long Ascii Strings)
Hi Don

I hope you find this useful.

One quick way to read the entire contents of a file is to append it into a
memo field. eg.

CREATE TABLE c:\junk (data M())
APPEND MEMO data FROM c:\junk.txt OVERWRITE

the field data now contains the entire contents of the file.
assuming each line is separated with CHR(13)+CHR(10)
You can find line breaks with AT(CHR(13),DATA)
eg.

lcdata=DATA
lcdata=lcdata+CHR(13)+CHR(10)+"  "   && you might need this if the last line
is missing a cr/lf
lcpos=AT( CHR(13),lcdata)
DO WHILE lcpos>0
    lcline=LEFT(lcdata,lcpos-1)
    && code to process line in here
    lcdata=SUBSTR(lcdata,lcpos+2)
ENDDO

The other way uses low level file commands.

lnfh=FOPEN("c:\junk.txt")    && open the file
DO WHILE NOT FEOF(lnfh)    &&loop until all done
    lcline=FGETS(lnfh,10000)    &&set the number to the maximum ever number
of characters in a line
    && lcline now contains a line from the file
    && you can  now parse the data in the line eg.
    lcdate=LEFT(lcline,8)    && eg 980910
    && next step depends on where you live.  && for UK
    lcdate=SUBSTR(lcdate,5,2)+"/"+SUBSTR(lcdate,3,2)+"/"+SUBSTR(lcdate,1,2)
    lddate=CTOD(lcdate)    && conver to an actual date
ENDDO
=FCLOSE(lnfh)

If your file is a fixed width table. eg. DATE starts a column 1 for 6
characters, AMOUNT starts at column 7 for 10 character etc.  You could set
up an array to deal with each field
DIMENSION lafields(2,3)
lafields(1,1)="Date"
lafields(1,2)=6
lafields(1,3)="D"
lafields(2,1)="Amount"
lafields(2,2)=10
lafields(2,3)="N"

Within your loop slice up the line string and call standard conversion
routines based on the type given in the 3 column of the array.

eg.
lcline=lcline+"  "
FOR lnCnt = 1 TO ALEN(laFields, 1)
    lcitem = LEFT( lcline, laFields(lncnt, 2) )
    DO CASE
        CASE laFields(lncnt, 3) ="D"
            lcresult=GETDATE(lcItem)    && user defined routine to get dates
from character string
        CASE laFields(lncnt, 3) ="N"
            lcresult=GETNUM(lcItem)    && user defined routine to get
NUMBERS from character string
        && ETC ETC
    ENDCASE
    lcline=SUBSTR(lcLine, laFields(lncnt, 2)+1)
ENDFOR

Similar techniques can be applied to comma delimited files.

Quote:

>First of all, I'm new to Foxpro and also I'm using Version 3.0a.

>I have to process long strings wwhic ar exported from my (Realworld)
>Accounting program.

>What I woudl liek to do is to have a program simply read the entire
string -
>just as it comes in the (exported) ASCII file, and process each line, and
>parse into fields which I can then access, etc.

>One problem which I have is that the numeric fields are exported as for eg
>below:

>                                               ..........
000001234560000+
>.............
>                                               ..........
000005678940000-
>..............
>note that the first is a positive figure and thesecond a negative.

>Now, when I use the Import wizard, (which I am reluctant to do since I, as
I
>said above, ideally I would like to have a program read the exported file
as
>is), and read this into a numeric field (created  previously) I find I am
>not getting the correct results.

>I also have a similar problem with date field which are exported as:

>                                                    ............ 980910
>..............

>I suppose the answer to the above is some long  routine to check each
>character individually etc etc!

>Any suggestions?

>Thanks in advance!



Sat, 03 Mar 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. STRTRAN() to fix ASCII: Error 1903: String is too long to fit

2. Long, long character string

3. Help: String to Long to fit!

4. anyone experienced with Dynazip and VFP???

5. Anyone have experience interfacing with Pixtools (graphics)?

6. FOXFIX Utility - Anyone with experience

7. SBT Experience anyone ?

8. Takes more time to process long file

9. Long record length in ASCII text files

10. Need a way to publish long HTML using REPORT...ASCII

11. progress bar with long SQL processing

12. String too long in PICTURE "@M"

 

 
Powered by phpBB® Forum Software