由多余的分配修复的莫名其妙的崩溃

inexplicable crash fixed by superfluous assignment

我正在测试我为格式化时间跨度而编写的一个小片段(例如,last change 5m23s ago),但不断出现我无法理解的错误。每次我尝试在对 ts() 的调用中直接使用循环变量 i 时,ASP 通知我 An error occurred...

'the function
function ts(s)
    dim m: m = CLng(s \ 60): s = s mod 60
    dim h: h = CLng(m \ 60): m = m mod 60
    ts = right("00" & h, 2) & "h" & _
         right("00" & m, 2) & "m" & _
         right("00" & s, 2) & "s" 
end function 

'the test
for i = 0 to 90000 step 15 
   '               response.write i & ": " & ts(i) & "<br />" 'an error has occurred
    dim j: j = i : response.write i & ": " & ts(j) & "<br />" 'works fine
next 

这到底是怎么回事?

为什么 ts(i) 每次都会出错?
鉴于此,为什么 j=i : ts(j) 可以正常工作?

这不可能是变量 i 的问题,因为它在 write 调用中运行良好。这是我尝试过的其他一些东西:

response.write i & ": "                     'no problem
'response.write ts(i)                       'crashes
'dim x: x = ts(i)                           'crashes
dim j: j = i                                'no problem
dim x: x = ts(j)                            'works
response.write x & "<br />"                 'works 
'response.write ts(j) & "<br />"            'also works 
'response.write i & ": " & ts(j) & "<br />" 'also works 

(最后,我知道据说有一种方法可以让 IIS 显示真正的错误。我很想听听如何在没有 RDP 访问网络服务器的情况下做到这一点。)

omegastripes 让我知道了。

显然在 VBScript 中,默认是传递参数 ByReference。
(从字面上看,我使用过的所有其他编程语言都传递原语 ByValue)

当我在函数内部更改 s 的值时,这导致了一个问题。

这些片段中的任何一个都可以正常工作:

function ts(ByVal s)
    ...
...
ts(i)

function ts(sec)
    dim s: s = sec
    ...
...
ts(i)

(或者,如 OP 中所述,在非循环迭代器变量中传递值)

function ts(s) 
... 
dim j: j = i: ts(j)