Jump to content
Server Maintenance This Week. ×

A found count - need help


This topic is 8536 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Here's the situation - Two number fields with the names 'found' and count'. Whenever a sort occurs, this script is triggered.

Loop

ExitLoopif [count=(currentfoundcount)]

SetField [count, count + 1]

SetField [found, found + 1]

PerformScript [next]

End Loop

As you can see this will go through the search results and add one to the existing number. This, by the way, is to track what was found over a website. All works well but the last record found gets add whatever the found count was. Why is this happening?

Thanks

Rich

------------------

Rich

Link to comment
Share on other sites

I'm afraid that I don't understand much of what you're trying to do with this script. Are found and count global fields? What do you mean by "the last record found gets add whatever the found count was?" by "(currentfoundcount)" do you mean "Status( CurrentFoundCount )" or is that another field?

Chuck

Link to comment
Share on other sites

Well, as I've said, this script will track what records have been found across a website. So when a search has been performed, each record found will get a +1 to it's 'found' field. This way I know how many times it's been accessed. But what is happening is the last record in the search is being added the status(currentfoundcount) to the number already there. The fields, count is global and is cleared at the end of the script. The found field is a number field.

Example:

A search for 'bars' comes up with 12 results. The script runs and each 'found' field in the search is added '1'. The twelth record is added '12' - So if the last record had a number of 10, after the script it would be 22, where all else would go to 11.

I think I forgot the status part of 'status(currentfoundcount) on the previous post.

Loop

ExitLoopif [count=status(currentfoundcount)]

SetField [count, count + 1]

SetField [found, found + 1]

PerformScript [next]

End Loop

Clear[select, count]

Hope this help.

Thanks

Rich

------------------

Rich

Link to comment
Share on other sites

Firstly, I'm assuming that what you posted is the entire script, because if it's not them my suggestions might not work...

What does the "Next" script do? If this script does nothing other than move to the next record then dump it and use the Go to Record step instead -- in which case you can delete the Exit Loop step too...???

Loop

SetField [count, count + 1]

SetField [found, found + 1]

Go to Record [next, exit after last]

End Loop

I'd pop a Go to Record [First] script step just before the loop to make sure the loop processes all of the found set.

Link to comment
Share on other sites

My first thought is that the field count is not a global field. If it is a number field, then the behavior your are getting makes sense.

If the count field exists only to tell you when you need to exit the loop, then Vaughan's script should do what you need, and you can actually take out the Set Field [ count, count + 1 ] step.

If the PerformScript [ next ] does more than simply a Go to Record/Request/Page [ Next ] then you could add a line at the beginning of the loop to Exit Loop If [ Status( CurrentRecordNumber ) = Status( CurrentFoundCount ) ]

Chuck

Link to comment
Share on other sites

OK, the latest script, now does not add to the last record. Here it is.

Go to Record/Request [First]

Loop

ExitLoopIf [status(CurrentRecordNumber) = status(currentrecordfound)]

SetField[found, found + 1]

Go to Record [Exit after Last, Next]

End Loop

As I said, this script now does nothing to the last record. Do you think the EndLoopif is triggering the script to end on the last before it does anything to the found field?

I appreciate both Vaughn and Chuck for helping with this matter.

Thanks

Rich

------------------

Rich

Link to comment
Share on other sites

That would work, I think, although there are certain script steps I tend to avoid unless there is no way around them. Replace is one of them. Copy and Paste are two more. I avoid Replace because it is layout specific, requiring the field to be on the layout when the step is run. This makes it easy to break the script later and not catch it right away. The Set Field step doesn't have this restriction.

Chuck

Link to comment
Share on other sites

Good point. I learned my scripting back in the bad old days of FM2.0 when there was no setfield function. I always make a habit of jumping to a working layout at the beginning of every script. My working layout has every field on it, and it is hidden from the user. I usually prefer the replace function because it's generally faster than looping.

One of the databases that I inherited had looping scripts that actually took 4 days to run (about 65,000 records). I rewrote the script using the replace function and got the time down to just a few hours. Not great, but better than having the system unavailable for a week.

Link to comment
Share on other sites

Which is faster, Replace or Looping? It kind of depends. A looping script with several SetFields can be faster than several Replaces. Depending upon the calculation, I've actually used a Replace AND a Loop in the same script to optimize speed. Testing helps. -bd

Link to comment
Share on other sites

This topic is 8536 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.