- #1
DaveC426913
Gold Member
- 22,497
- 6,168
Grr! This is flummoxing me!
I want to add every combination of cells in n rows that will be input be textfields.
field 1: 12
field 2: 678
field 3: 45
field n: -
And user is looking for sum: 12
Results in:
164
165 is a hit!
174 is a hit!
175
184
185
264 is a hit!
265
274
275
284
285
Every time I write a nested loop, I run into trouble. I need a counter for EACH field. (My code below advances the cell counter for ALL rows at the same time.)
(This is essentially JavaScript but just treat it as pseudocode. I can transcribe from pseudocode.)
I want to add every combination of cells in n rows that will be input be textfields.
- The number of rows is flexible. It is defined when the appropriate number of textfields have strings of numbers in them.
- Each row will have its own number of cells in it, determined by the data in the textfield.
- I want to sum one from each field.
field 1: 12
field 2: 678
field 3: 45
field n: -
And user is looking for sum: 12
Results in:
164
165 is a hit!
174 is a hit!
175
184
185
264 is a hit!
265
274
275
284
285
Every time I write a nested loop, I run into trouble. I need a counter for EACH field. (My code below advances the cell counter for ALL rows at the same time.)
(This is essentially JavaScript but just treat it as pseudocode. I can transcribe from pseudocode.)
Code:
arr = loadFieldDataIntoArray();
var lookingToMatchSum = loadSum();
for (field=0; field<arr.length-1; field++ ){
for (for cell=0; cell<arr[field]; cell++){
var iAns = 0;
var sAns = "";
for (sumFields=0;sumFields<arr.length-1; sumFields++){
var thisFieldCellValue = parseInt(arr[sumFields].substring(cell,1));
iAns += thisFieldCellValue;
sAns += thisFieldCellValue;
}
if (iAns==lookingToMatchSum){
document.write(sAns " is a hit!");
}
}
}