RichJr Posted December 5, 2000 Posted December 5, 2000 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
Chuck Posted December 5, 2000 Posted December 5, 2000 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
RichJr Posted December 5, 2000 Author Posted December 5, 2000 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
Vaughan Posted December 6, 2000 Posted December 6, 2000 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.
Chuck Posted December 6, 2000 Posted December 6, 2000 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
RichJr Posted December 6, 2000 Author Posted December 6, 2000 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
Chuck Posted December 6, 2000 Posted December 6, 2000 Transpose the third and fourth lines: Go to Record/Request [First] Loop
RichJr Posted December 7, 2000 Author Posted December 7, 2000 Chuck - Thanks very much. As your website says, You are an expert in this field. It now works properly. ------------------ Rich
BobWeaver Posted December 10, 2000 Posted December 10, 2000 Wouldn't it just be easier to use the following for a script? Replace [found, Replace data: Calculation:, found + 1]
Chuck Posted December 11, 2000 Posted December 11, 2000 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
BobWeaver Posted December 12, 2000 Posted December 12, 2000 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.
LiveOak Posted December 12, 2000 Posted December 12, 2000 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
Recommended Posts
This topic is 8752 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 accountSign in
Already have an account? Sign in here.
Sign In Now