I haven't created any fields/ names yet, I was going to based on whatever example code giving.
OK. Let's say they are called Code1 to Code32 and you want to count all the fields whose values start with "A" and end with "B" and show the result in a field called Total2. You can use this code as the custom calculation script of Total2:
var total = 0;
for (var i=1; i<=32; i++) {
var f = this.getField("Code"+i).valueAsString;
var v = f.valueAsString;
if (v.charAt(0)=="A" && v.charAt(v.length-1)=="B") total++;
}
event.value = total;
You can easily adjust this code for the other total fields by changing the strings in line #5 to "A"/"A" and "B"/"A" for Total1 and Total3, respectively.