For i = 0 To StockDataSet.Tables("Stock").Rows.Count - 1 'repeat for every row in the dataset 'calculating number sold dr = StockDataSet.Tables("Stock").Rows(i) 'this is making dr = row i in the table stock(i being a incrementing variable)' totalsold = totalsold + Int(dr("Number Sold")) 'makes totalsold equal to the total sold in the table + the number sold 'calculating profit profit = profit + (CDbl(dr("Price")) * CDbl(dr("Number Sold"))) 'calculating possible profit posprofit = posprofit + (CDbl(dr("Price")) * (CDbl(dr("Number In Stock")) + CDbl(dr("Number Sold")))) 'calculating percentage of stock sold percentage = (profit / posprofit) * 100 Next