Problems Total on A SubForm

Problems Total on A SubForm

Im trying to Total the cost of a list of products in a SubForm. I take a look for the same script in the New Order form for the Order Management app, with no satisfactory results. I use this code:

This Code is Located on User Input in the field where I change the quantities 

row.subtotalcost=(row.pcostadd  *  row.pqty);
totaltemp=0.0;
for each rowvar in Subformpadd
{
totaltemp = (totaltemp + rowvar.subtotalcost);
}

The error message I got when I fill the SubForm is:
 Error in performing the operation +: Error
Accessing the value rowvar.{1}

It seems the rowvar always got NULL