![四分之一的值未传递到函数中](https://linux22.com/image/1377098/%E5%9B%9B%E5%88%86%E4%B9%8B%E4%B8%80%E7%9A%84%E5%80%BC%E6%9C%AA%E4%BC%A0%E9%80%92%E5%88%B0%E5%87%BD%E6%95%B0%E4%B8%AD.png)
我尝试在函数中传递 4 个值,但第四个值似乎未传递且始终为零。这是我的代码:
Sub romberg()
'
' romberg Macro
' 3 Sep 2013
'
Dim x0 As Long
Dim fx As Long
Dim x1 As Long
Dim stepsize As Long
Dim J, K, c As Long
Range("A12:N65536").Clear
Columns("A:N").HorizontalAlignment = xlCenter
'column i
'J=0
x0 = Cells(9, 2)
fx = Cells(9, 3)
x1 = Cells(9, 4)
stepsize = Cells(9, 5)
Cells(13, 4) = t(x0, fx, x1, stepsize)
.
.
.
end sub
Public Function t(a As Long, f As Long, b As Long, h As Long)
Dim J As Integer
Sheets("T").Activate
Range("A8:D65536").Clear
Columns("A:D").HorizontalAlignment = xlCenter
Cells(3, 1) = a
Cells(3, 2) = f
Cells(3, 3) = b
Cells(3, 4) = h
.
.
.
t = Cells(3, 6)
End Function
答案1
当您尝试传递一个 cell 类型时,您指出 stepsize 是一种 long 类型。
更改此代码
stepsize = Cells(9, 5)
Cells(13, 4) = t(x0, fx, x1, stepsize)
到
stepsize = Cells(9, 5).value
Cells(13, 4).value = t(x0, fx, x1, stepsize)