Help regarding updating field from subform to main form.

Help regarding updating field from subform to main form.

I am facing a problem regarding the updating field from sub form to main form. There is not relation between main form and sub form.
 
I have added a code on   add row  of sub form. But it is not updating the field.

sum = 0;
for each SubForm r in Shipping
{
    g = (sum  +  row.List_Price.toLong());
}
input.Total_to=g;

Please reply asap.