Vfp Do While Found Continue Loop

INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

LOCATE() Command

LOCATE() Command

(OP)

I am working with some legacy code written by an old employee.  He used the LOCATE() command with quite a bit of frequency and I am finding that the command did not always work right.  Is there a better alternative to this method?

Perhaps SQL?

Select 1
Use PIC_DATE_TOTAL
Select 2
Use D:\sap_SVC\PIC_tot_out
Select 2
Go TOP
Scan
    Select 2
    Locate FOR ship_date=A->DATE_rec&& This breaks      quite often
    If FOUND()
        Replace DOA_QTY WITH A->qty
        Replace QTY_FAIL WITH A->CLOSE_TIME
        If qty>0
            Replace PERCENT WITH DOA_QTY/qty
            Replace FAIL_PCT WITH QTY_FAIL/qty
        Endif >0

    Endif
    Select 1
    Skip
Endscan

RE: LOCATE() Command

You've posted this code before, but what is this line supposed to do?

Replace DOA_QTY WITH A->qty

I've never seen the "->"  (arrow?) command. Is this even valid foxpro? If so, what does that command do? Can you explain what it supposed to do?

RE: LOCATE() Command

(OP)

It is comparing the the two tables for a specific set of data.  In this case it it locating for the date_rec=ship_date

In other words it is saying this.

Replace DOA_QTY with Pic_date_tot.qty

Could the -> be messing up the locate?

RE: LOCATE() Command

The arrow -> was the "way back when" method of specifying a field in a table or work area.

Select 1
Use Table1
Replace Table1->FName with "Moe"
Replace A->FName with "Moe"

Same thing  ;)

Dave

The 2nd mouse gets the cheese.

RE: LOCATE() Command

(OP)

Glad that we have focused on the ->, but can anyone tell me about why this LOCATE() command is not working correctly?

RE: LOCATE() Command

PS:

Locate will work without an index on the field but the Rushmore kicks in when you do. Check and make sure the firled you are "Locating" is indexed.

Dave

The 2nd mouse gets the cheese.

RE: LOCATE() Command

(OP)

this is the code I run prior to the previous code I posted.

I do index and then total then run the LOCATE().  Are you saying I shouldn't do that?

Index ON DATE_rec TO ANY
Total ON DATE_rec TO PIC_DATE_TOTAL

OH, BTW, I think the reason that it is breaking is that in one table I am referencing items from 02/2000 till now.  When I index it starts at 02/2000 to now.

But the table I am locating with starts at 05/2000.  Shouldn't the locate() still work?

RE: LOCATE() Command

Is the code you posted complete?  I'd
Set Order To someindex in the work area
Do a Locate for the value in the field above the scan
If Found() Do a Scan with a WHile condition or a do while loop

Try to Set Order To  in the work area after the Use statement and do the locate before you start processing in the loop.  If Found()  .T.  then Scan While condition remains or you could use a Do While.

Hope this helps

Dave

The 2nd mouse gets the cheese.

RE: LOCATE() Command

(OP)

I think I know what you are talking about can you put it into some kind of context?  Logic?

RE: LOCATE() Command

Something like...

Select 1
Use PIC_DATE_TOTAL
Set Order To ?  && maybe index on DATE_rec
Go Top
Select 2
Use D:\sap_SVC\PIC_tot_out
Set Order To ?  && maybe index on ship_date
Go TOP
Select 1
Do While EOF() = .F.
      Select 2
      Locate FOR ship_date=A->DATE_rec
      If FOUND()
            Do While  ship_date=A->DATE_rec
                  Replace DOA_QTY WITH A->qty
                  Replace QTY_FAIL WITH A->CLOSE_TIME
                  If qty>0
                        Replace PERCENT WITH DOA_QTY/qty
                        Replace FAIL_PCT WITH QTY_FAIL/qty
                 Endif >0
                 Skip
            EndDo
      EndIf
      Select 1
      Skip
EndDo

Remember, the A-> refers to the work area and can be replaced with table name.

Good Luck  :)

The 2nd mouse gets the cheese.

RE: LOCATE() Command

If its indexed, wouldn't a seek be faster?

-Pete

RE: LOCATE() Command

(OP)

Thank you all for the great help.

RE: LOCATE() Command

Hi BlindPete,

SEEK is supposed to be faster than a LOCATE but what's a couple of milliseconds.  Unless the files are really huge, there won't be any significant difference in processing time.

I do stand corrected though.    ;)

Dave

The 2nd mouse gets the cheese.

RE: LOCATE() Command

You are abosolutely correct.

I realize now my comment could be mis-read as me being a "smart*ss"  I was trying to be helpful only.  You are correct to continue using the LOCATE command in your detailed example.  Switching to SEEK might have only increased  stlrain95 confusion.

-Pete

RE: LOCATE() Command

(OP)

SIMMA!!  There is no confusion, just wanted a little clarification.

thank you,

RE: LOCATE() Command

Hey There BlindPete,

No "smart ass" detected in your original comment - you're right.  That's what makes this site a great resource - everybody contributes.

Dave

The 2nd mouse gets the cheese.

RE: LOCATE() Command

Here are some suggestions on your code:

Select 1
Use PIC_DATE_TOTAL
Select 2
Use D:\sap_SVC\PIC_tot_out
* The next line is unnecessary; the same work area is still
*   selected after the USE command above.
* Select 2

* The next line is unnecessary: when using a new table,
*   it always starts at the top.
* Go TOP
Scan
    Select 2
    Locate FOR ship_date=A->DATE_rec&& This breaks      quite often
    If FOUND()
        Replace DOA_QTY WITH A->qty
        Replace QTY_FAIL WITH A->CLOSE_TIME
        If qty>0
            Replace PERCENT WITH DOA_QTY/qty
            Replace FAIL_PCT WITH QTY_FAIL/qty
        Endif >0

    Endif
* The next line is unnecessary: ENDSCAN always takes you
*   back to the table you were in when the SCAN command
*   was encountered.
*    Select 1
* The next line is not only unnecessary but <FONT COLOR="RED">is
*   probably the source of your problems</FONT>. ENDSCAN
*   will automatically issue the "SKIP" command; having
*   "SKIP" here also will cause every other record to
*   be missed.
*    Skip
Endscan

HTH.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Join | Advertise

Copyright © 1998-2022 engineering.com, Inc. All rights reserved.
Unauthorized reproduction or linking forbidden without expressed written permission. Registration on or use of this site constitutes acceptance of our Privacy Policy.

Engineering.com

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

  • Tek-Tips ForumsTalk To Other Members
  • Notification Of Responses To Questions
  • Favorite Forums One Click Access
  • Keyword Search Of All Posts, And More...

Register now while it's still free!

Already a member? Close this window and log in.

Join Us Close

hogansprill.blogspot.com

Source: https://www.tek-tips.com/viewthread.cfm?qid=259031

0 Response to "Vfp Do While Found Continue Loop"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel