2013-07-22 95 views
1

我試圖在Excel VBA運行Rungenkutta差的問題 程序如下VBA Excel的編譯錯誤:預期子,函數,或屬性

Sub Rungenkutta() 


Dim Noofitrations As Integer 
Dim n As Integer 
Dim ii As Integer 
Noofitrations = Cells(2, 10) 
n = Cells(3, 10) 
h = Cells(3, 4) 
col = 8 
x0 = Cells(col, 9) 
y0 = Cells(col, 10) 

For i = 1 To Noofitrations 

Cells(7, 3) = x0 
Cells(7, 4) = y0 
xn = x0 + h 
yn = y0 + Cells(18, 3) 

ii i Mod n 
If ii = 0 Then 
    col = col + 1 
    Cells(col, 9) = xn 
    Cells(col, 10) = yn 
End If 
x0 = xn 
y0 = yn 

Next 


End Sub 

,但在運行我得到「VBA Excel的編譯錯誤:預計SUB,功能,或財產」

我不理解我該做些什麼來運行程序

+0

當它失敗時它指向一行代碼嗎? –

+0

'ii我Mod n'不合法VBA - 應該是'ii = i Mod n'而不是? – barrowc

回答

2

你的問題是與Mod運算符。 VBA不能識別您提供的語法。

這裏是Mod運算符的一些文件 - http://msdn.microsoft.com/en-us/library/se0w9esz.aspx

釷Mod運算符是一個二元運算符和需要一個左,一個正確的說法。

您需要更改

ii i Mod n 

ii = i Mod n 

這裏是你提供的修改後的例子。

Sub Rungenkutta() 


Dim Noofitrations As Integer 
Dim n As Integer 
Dim ii As Integer 
Noofitrations = Cells(2, 10) 
n = Cells(3, 10) 
h = Cells(3, 4) 
col = 8 
x0 = Cells(col, 9) 
y0 = Cells(col, 10) 

For i = 1 To Noofitrations 

Cells(7, 3) = x0 
Cells(7, 4) = y0 
xn = x0 + h 
yn = y0 + Cells(18, 3) 

ii = i Mod n 
If ii = 0 Then 
    col = col + 1 
    Cells(col, 9) = xn 
    Cells(col, 10) = yn 
End If 
x0 = xn 
y0 = yn 

Next 


End Sub 
相關問題