四分之一的值未传递到函数中

四分之一的值未传递到函数中

我尝试在函数中传递 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)

相关内容