Calculating integral of earths orbit but with visual basic.

1. Oct 23, 2012

Lengalicious

1. The problem statement, all variables and given/known data
Ok for starters, I wasn't entirely sure whether this was supposed to go under physics or comp sci, this is a 'physics' problem I believe but done through visual basic, anyways.

So I have a program where the earth is animated to orbit the sun based on Newtons laws, I need to calculate the definite integral from X = start of orbit, to X = 0 ∫ Y(x) dx based on the linear interpolation formula shown below.

2. Relevant equations

Extended linear interpolation formula: 1/2*(f(x1) + f(x2))*h + 1/2*(f(x3) + f(x4))*h + . . + 1/2*(f(xn-1) + f(xn))*h

where h is supposed to be x2-x1 for the 1st term then x3-x2 for the next term etc.

3. The attempt at a solution

Please note that before this question I had a question to integrate ∫ 1/R(t)2 dt from where the earth starts to X=0 before the one I'm asking and I achieved this by doing a sum within the While loop, ie.
Code (Text):
While x > 0

Sum = Sum + Function

End While

Then taking away the 1/2*(1st + last) terms to adjust for the error in the extended interpolation formula.

Now for the question i'm completely stuck all I can suggest to myself is doing another summation during the loop of the function 'Y' but then I have to somehow adjust the answer so that it gives the same answer as the formula but I don't understand how to multiply each term by 'h' in visual basic? Any suggestions?