April 1, 200718 yr Newbies I have many grade fields that all require a calculation to get the subject grade transformed into a number so they can be averaged for the different semesters. The calculation I am using is: Position("FDCBA"; Left(fieldLet1; 1); 1; 1) - 1 + Choose(Position("+-"; Right(fieldLet1; 1); 1; 1); 0; .33; -.33). This works fine but I don't want to duplicate it for each subject. Is there a way to write it once (maybe as a custom function) and use it for all the subject grades?
April 1, 200718 yr Sure, you just define it as a custom function with a name, like ConvertGradeLetter, with a parameter of gradeLetter: ConvertGradeLetter( gradeLetter ) = Position("FDCBA"; Left(gradeLetter; 1); 1; 1) - 1 + Choose(Position("+-"; Right(gradeLetter; 1); 1; 1); 0; .33; -.33)
April 1, 200718 yr Author Newbies What am I missing? Doesn't any calculation that has a reference GradeLetter always need a particular field called GradeLetter? I have many different fields with letter grades.
April 1, 200718 yr So is better ? /* ConvertToGradeLetter ( text ) custom function */ Position("FDCBA"; Left(text; 1); 1; 1) - 1 + Choose(Position("+-"; Right(text; 1); 1; 1); 0; .33; -.33)
April 2, 200718 yr What am I missing? ... I have many different fields with letter grades. You should have ONE field, with one calculation - but many (related) records.
April 2, 200718 yr gradeLetter is a parameter to the custom function, when you use the custom function, you pass in the field you want it computed for as the argument - that's how the custom functions let you reuse the calculation in multiple places.
April 2, 200718 yr I just noticed the title of this thread. A calculation with no reference returns a constant (unless it incorporates one of the Get() functions, e.g. current date). Since your result is a function of input, the input needs to referenced. If you have 20 input fields (letter grades), you will need 20 calculation fields, each referencing its own input field. It doesn't matter if you use a custom function or not. A custom function would merely shorten the formula. The real problem here is the data structure. You could use a repeating field for the grades, and a repeating calculation field for the translation, but that would be only a partial solution.
Create an account or sign in to comment