Help again needed for rows in a subform

Help again needed for rows in a subform

I currently have this in code in order to total quantity on hand from input in a subform

if(SubForm.Quantity_to_Distribute != null)

{

x = Add_New_PPE[ID == input.SubForm.Select_PPE_Description];

x.Total_On_Hand=input.SubForm.Total_PPE_On_Hand - input.SubForm.Quantity_to_Distribute;

}

else if(SubForm.Quantity_to_Return != null)

{

x = Add_New_PPE[ID == input.SubForm.Select_PPE_Description];

x.Total_On_Hand=input.SubForm.Total_PPE_On_Hand + input.SubForm.Quantity_to_Return;

}

It works for the first item but not for subsequent items

 I tried to use row instead of input  as I did for populating fields but I am getting an error that variable row is not defined.
This is what I tried. 

Test if(Add_New_PPE[ID = input.SubForm.Quantity_to_Distribute] != null)

{

x = Add_New_PPE[ID == row.Total_PPE_On_Hand];

x.Total_On_Hand= row.SubForm.Total_PPE_On_Hand - row.SubForm.Quantity_to_Distribute;

}

else if(Add_New_PPE[ID = input.SubForm.Quantity_to_return] != null)

{

x = Add_New_PPE[ID == row.Select_PPE_Description];

x.Total_On_Hand=row.SubForm.Total_PPE_On_Hand + row.SubForm.Quantity_to_Return;

}