I am a new programmer, and I am trying to write a code that cycles though an excel spread sheet. Time is in the first column displace in the second and velocity in the third. I would like to process the data one row at a time. I am getting the runtime error when I try to calc acceleration (xddot=...). However, I think the problem stems from the arrays. Is there another way I should be going about this.
thanks in advance.
Private Sub Command1_Click()
Dim s As Integer
Dim xddot As Double
Dim timestep As Integer
Dim z, h As Double
Dim row1, endrow As Integer
Dim time(), x(), xdot() As Long
s = Range(Range("A14"), Range("A65536").End(xlUp)).Count
z = 1
endrow = Range("A65536").End(xlUp).ROW
For timestep = 1 To s
For row1 = 14 To endrow
ReDim time(1 To s, 1), x(1 To s, 2), xdot(1 To s, 3) As Long
xddot = ((xdot(timestep, 3) - xdot(timestep - 1, 3)) / (time(timestep, 1) - time(timestep - 1, 1)))
Dim k1, k2, k3, k4 As Double
Dim i As Long
h = xddot - Cells(row1 - 1, 6).Value
k1 = h * f(xddot, z)
k2 = h * f(xddot + h / 2, z + k1 / 2)
k3 = h * f(xddot + h / 2, z + k2 / 2)
k4 = h * f(xddot + h, z + k3)
z = z + k1 / 6 + k2 / 3 + k3 / 3 + k4 / 6
Print "when xdot = "; xdot(timestep); "z = "; z
Dim f0 As Double
Dim ft As Double
ft = fc(z, x, xdot, xddot) - f0
Range("E14").Value = ft
Next row1
Next timestep
End Sub
thanks in advance.
Private Sub Command1_Click()
Dim s As Integer
Dim xddot As Double
Dim timestep As Integer
Dim z, h As Double
Dim row1, endrow As Integer
Dim time(), x(), xdot() As Long
s = Range(Range("A14"), Range("A65536").End(xlUp)).Count
z = 1
endrow = Range("A65536").End(xlUp).ROW
For timestep = 1 To s
For row1 = 14 To endrow
ReDim time(1 To s, 1), x(1 To s, 2), xdot(1 To s, 3) As Long
xddot = ((xdot(timestep, 3) - xdot(timestep - 1, 3)) / (time(timestep, 1) - time(timestep - 1, 1)))
Dim k1, k2, k3, k4 As Double
Dim i As Long
h = xddot - Cells(row1 - 1, 6).Value
k1 = h * f(xddot, z)
k2 = h * f(xddot + h / 2, z + k1 / 2)
k3 = h * f(xddot + h / 2, z + k2 / 2)
k4 = h * f(xddot + h, z + k3)
z = z + k1 / 6 + k2 / 3 + k3 / 3 + k4 / 6
Print "when xdot = "; xdot(timestep); "z = "; z
Dim f0 As Double
Dim ft As Double
ft = fc(z, x, xdot, xddot) - f0
Range("E14").Value = ft
Next row1
Next timestep
End Sub