Re: VFP9SP1 How to determine # of rows using LLFF operations

Author: MB Software Solutions, LLC

Posted: 2011-08-09 at 15:23:31

On 8/9/2011 3:02 PM, Mike Copeland wrote:

>> Mike,

>>

>> It would be a two pass thing, or a best guess. I would go with the best

>> guess.

>> A tight loop getting the data and dumping it as you get a total count, then

>> return to the top and begin processing.

>> If you did this, since you have multiple types of data in the file, you

>> could get a count of each type. Then show the progress of each type as you

>> do the real processing.

>>

>> The best guess, FSEEK() to the end returns the total number of bytes. You

>> can use this and add the bytes of each line to show the complete progress.

>>

>>

> Just test for FEOF() with each iteration. I've never had a problem doing

> that to "find the end."

Oh I know to use FEOF to test for the end of the loop, but I was

thinking that I could use FSIZE (with SET COMPATIBLE DB4) to get the

filesize in bytes, and then divide that by the record length, but

apparently my logic is flawed, because my loop was telling me

"Processing record 990123 of 636789" -- LOL

Doing the tight loop as Tracy mentioned should work, but it seems like a

kludge (but a necessary one!). I *do* like the idea of telling the user

how many records of each type ahead of time though!

Here's my logic so far (but the record count is off by seemingly twice

as much. Can you see why??!?!?

lcFileType = UPPER(RIGHT(JUSTSTEM(This.InputFile),2))

DO CASE

CASE lcFileType = "OP"

lnLength = 550

lnRecPosn = 54

* put other lengths in later after OP passes testing

OTHERWISE

SET STEP ON

ENDCASE

lnRows = lnFileSize / lnLength

liHandle = FOPEN(this.InputFile)

liCnt = 0

DO WHILE NOT FEOF(liHandle)

m.liCnt = m.liCnt + 1

m.LineOfText = FGETS(m.liHandle,m.lnLength) && according to VFP Help,

rec ptr is moved, so I don't need to use FSEEK

m.RecordType = SUBSTR(m.LineOfText,m.lnRecPosn,1)

WAIT WINDOW NOWAIT "Processing line " + ALLTRIM(STR(liCnt)) + " of " +

ALLTRIM(STR(lnRows))

DO CASE

CASE m.RecordType = "1"

This.ProcessType1(m.LineOfText)

CASE m.RecordType = "2"

This.ProcessType2(m.LineOfText)

CASE m.RecordType = "3"

This.ProcessType3(m.LineOfText)

CASE m.RecordType = "4"

This.ProcessType4(m.LineOfText)

OTHERWISE

* unknown type or EOF marker

IF LEN(m.LineOfText) > 1

SET STEP ON

This.LogIt("UT", "", m.LineOfText)

m.RogueCntr = m.RogueCntr + 1

This.ErrorCondition = .T.

*** mjb 2011/06/08 - changing so that if ANY errors occur,

program does not continue towards output file.

m.MsgTxt = "This file has an error. Processing will not

continue." + CHR(13)

m.MsgTxt = m.MsgTxt + "Please review DSHImportExport.LOG to see

the invalid data."

MESSAGEBOX(m.MsgTxt, 16, "Error: Invalid Data")

m.RetVal = .F.

EXIT

ENDIF

ENDCASE

ENDDO

FCLOSE(liHandle)

--

Mike Babcock, MCP

MB Software Solutions, LLC

President, Chief Software Architect

http://mbsoftwaresolutions.com

http://fabmate.com

http://twitter.com/mbabcock16

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/profox

OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/4E418933.5000909@mbsoftwaresolutions.com

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2011 MB Software Solutions, LLC