July 22, 200421 yr I'm a scripting newbie, so please bear with me. I've done a couple of looping scripts with numerical loop invariants, but don't know how to traverse the DB based on contents of a particular field. Ex. Given database with two fields MANUFACTURER and COMPUTERTYPE, I want to loop through the DB once for each unique value of MANUFACTURER. How do I structure a Loop to do something like the following pseudocode: for each MANUFACTURER select (MANUFACTURER, COMPUTERTYPE); <do other stuff I'll fill in here> done I'm a scripting newbie, other than really minor stuff...
July 22, 200421 yr Is this for a report? If so you can use sub-summaries to separate the Manufacturers.
July 22, 200421 yr If this is not for a simple sub-summary report, then something like this would allow you to do something at each unique manufacturer: Go to Record/Request/Page [ First ] Set Field [ gManufacturer , "" ] Loop If [ gManufacturer <> Manufacturer ] # Next manufacturer found. Do something cool Set Field [ gManufacturer , Manufacturer ] End If Go to Record/Request/Page [ Exit after last, Next ] End Loop gManufacturer is just a global that remembers the manufacturer that you were on. If you are planning on running something like this often, or with large sets of data, then there are more efficient ways to do this.
July 22, 200421 yr Author That makes sense, and I'll try it, but it is for a fairly large dataset. Mind sharing that "more efficient" way? Thanks! P.S., No, a sub-summary report won't work for it.
July 22, 200421 yr Two possibilities come to mind: A. Normalize the Manufacturer data into another file. Then you can easily loop through those. If needed, you can easily jump to the related Computer records to process records for a particular manufacturer. B. Add two fields: Count of Records (summary, count of Record ID) and Count by Manufacturer (calculation, number result) = GetSummary(Count of Records, Manufacturer). And use a different global, gRecordNum. Use a script like this to loop through: Sort [ Restore ] //Sort by Manufacturer Go to Record/Request/Page [ First ] Set Field [ gRecordNum , 1 ] //Global for keeping track of the current record number Loop # Next manufacturer found. Do something cool Set Field [ gRecordNum , gRecordNum + Count by Manufacturer ] Exit Loop If [ gRecordNum Status(CurrentFoundCount) ] Go to Record/Request/Page [ gRecordNum ] End Loop
Create an account or sign in to comment