Expand my Community achievements bar.

Looping through variable instances

Avatar

Level 2

Hi All.

Noob.Person1[Scott] needs a bit of syntax help.

What's the correct way to handle the "l" and "f" variables in the loop below? It doesn't like the f(i) business.

if (xfa.resolveNode("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+rowNum+"]").Locations.Location1.rawValue != null

{

l1 = xfa.resolveNode("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+rowNum+"]").Locations.Location1.rawValue;

l2 = xfa.resolveNode("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+rowNum+"]").Locations.Location2.rawValue;

l3 = xfa.resolveNode("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+rowNum+"]").Locations.Location3.rawValue;

l4 = xfa.resolveNode("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+rowNum+"]").Locations.Location4.rawValue;

l5 = xfa.resolveNode("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+rowNum+"]").Locations.Location5.rawValue;

for (var i=1; i<6; i++)

{

if (l(i)== 15)

{

var f(i) = Locations.Location.item(i).somExpression;

xfa.host.resetData(f(i));

}

trip = distance [l(i)] [l(i + 1)];

this.rawValue = trip + trip;

}

Thanks.

9 Replies

Avatar

Level 8

You can try:

for (var i=1; i<6; i++)

{

if (xfa.resolveNode("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+row Num+"].Locations.Location"+i).rawValue == 15)

{

xfa.host.resetData(xfa.resolveNode("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+row Num+"].Locations.Location"+i).somExpression);

}

Not sure what you're trying to do with:

trip = distance [l(i)] [l(i + 1)];

this.rawValue = trip + trip;

Kyle

Avatar

Level 2

Thanks a mil.

>>>Not sure what you're trying to do with:

Don't worry about the last line; it's a mistake.

But this:

trip = distance [l(i)] [l(i + 1)];

Is going to a two dimensional array to look up some distances. With my old script I used:

trip1 = distance [from1] [to1];

The new script may work too; I haven't had a chance to try it.

BTW...I saw your suggestion for Bruce's cookbook, but cookbooks.adobe.com isn't working for me today. You?

Avatar

Level 8

Ya I think they're getting rid it. It's not working for me either. It's shame really.

Kyle

Avatar

Level 8

I just realized that:

xfa.host.resetData(xfa.resolveNode("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+rowNum+"].Locations.Location"+i).somExpression);

is redundant and could just be:

xfa.host.resetData("ExpenseClaim.Page2.DistanceRecord.TableKM.Row1["+rowNum+"].Locations.Location"+i)

Kyle

Avatar

Level 2

It's choking on this:

trip = distance [l + i] [l + (i + 1)]

Any idea how to creat an expression which will result in this:

trip = distance [ l1] [l2] // first time around

trip = distance [l2] [l3] //second time around

trip = distance [l3] [l4] //third time around

etc.....

Tried this:

trip = distance ["l"+ i] ["l" + i + 1];

but no.    :-(

Avatar

Level 8

I'm not sure what l and i are suppose to be but if distance is an array you shouldn't be passing a string to it (distance["l"+i]["l"+i+1]). Between the brackets should be an integer representing the index of the array.

It sounds like you should be using objects instead of arrays.

Again, it's hard for me to help when I don't know exactly what you're trying to accomplish.

Kyle

Avatar

Level 2

>>>Between the brackets should be an integer representing the index of the array.

Zackly.

So l1, l2, l3 etc are variables holding integers of the array indicies.

I'd like the loop to use "i" to increment the variable names so that when the loop executes, these statements are formed:

trip = distance [ l1] [l2]  //first time around the loop

trip = distance [l2] [l3]  //second time around the loop

trip = distance [l3] [l4]  //third time around the loop

Avatar

Level 8

Instead of declaring them as variables, use them as parameters in an object:

var myObject={l1:1,l2:2};//you can replace the integer values with a variable

//then use them in your array as:

trip=distance[myObject["l"+i]][myObject["l"+i+1]];

//etc etc

Kyle