Marcel1 Posted February 27, 2007 Posted February 27, 2007 This seems trivial, but... I am having a little difficulty with a script that is intended to examine the contents of a field, and if it is "A", add 1 to a field in a related record, if it is "B", add 1 to another field in a related record, etc.. Basically I am making a counter script to record the number of times a particular value occurs in a field, that I can run on a found subset of my main table. However, I am having a little trouble creating the calculation. Does anyone know how to do this? Marcel
Genx Posted February 27, 2007 Posted February 27, 2007 ... You could just use a summary field to do this and sub summarize by your letter field to get you a count. But if you are desperate to use the script for whatever reason.. If[Field = "A"] Set Field[RelatedField::A ; 1 ] Else If[Field = "B"] Set Field[RelatedField:: ; 1 ] ... Else If[Field = "Z"] Set Field[RelatedField::Z ; 1 ] End If
Marcel1 Posted February 27, 2007 Author Posted February 27, 2007 (edited) Hi thanks, Sorry should have been more clear; I am actually trying to mathematically increment the present value of the related field by 1 (ie if the present value in the related field is 6 and the conditions are met, the value after the script step would be 7). I am not desperate to use a script, and if there is an easier way, by all means.. I am not sure how to create a summary field to do what I am hoping to do. I did look up summary fields, but it is not clear to me how I can use them to calculate sums on a found subset of records in the main table. M Edited February 27, 2007 by Guest
Genx Posted February 27, 2007 Posted February 27, 2007 Do you want to use this for the purpose of reporting or only on screen?
Lee Smith Posted February 27, 2007 Posted February 27, 2007 If the calculation field was a different field than B, you could use a calculation: NewField (Calculation, Number) = Case ( A::A = "Zee" ; B + 1 ) However, in order to change the same field, you would have to use a Script. If [ A::A = "Zee" ] Set Field [ Related::; Related:: + 1 ] End If HTH Lee
Marcel1 Posted February 27, 2007 Author Posted February 27, 2007 Yes, I am hoping to use this for reporting. OK so I tried inserting the calculation If [ A::A = "Zee" ] Set Field [ Related::; Related:: + 1 ] End If into the script, and this morning for some reason it works just fine. Thanks for the help! M
T-Square Posted February 27, 2007 Posted February 27, 2007 Marcel-- Running a script through every record just to count values is a slow way to solve the problem--especially as the file grows. Look at what Genx first said: You can accomplish what you want--without a script--by creating a report that uses a summary field and then breaking on the field's value. Now, if you need to track (for documentational purposes) the values over time, you could still use a relational approach to capture these values by creating a global field to work in conjunction with your summary field. Build a relationship between the global field and the field, set your summary to count through that relationship, and then loop through the field values in your script. The summary field would give you a total for each value without having to read every record in the table, and you could store that. I suspect it would go much faster this way. HTH, David
Recommended Posts
This topic is 6540 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