如何清除vbscript中数组的内容? [英] How to clear the contents of an array in vbscript?
问题描述
我在函数库中声明了一个二维数组并将其与测试相关联.在测试的 action1 中,我尝试使用erase"语句清除数组.
我的代码 -
在函数库中,
I have declared a two dimensional array in the function library and associated it with a test. In action1 of the test, I tried to clear the array using "erase" statement.
My code -
In Function Library,
Dim strVerifyAry(25,6)
在行动 1,
erase strVerifyAry
错误信息
Run Error - Type mismatch: 'Erase'
如何清除这个数组的内容?
How to clear the contents of this array?
推荐答案
在纯 VBScript 中对我有用,因此很可能是 QTP 用于运行 VBScript 代码的引擎的问题.您应该能够为二维数组模拟 Erase
的行为,如下所示:
Works for me in plain VBScript, so it's most likely an issue with whatever engine QTP uses for running VBScript code. You should be able to emulate the behavior of Erase
for a 2-dimensional array like this:
Sub EraseArray(ByRef arr)
For i = 0 To UBound(arr, 1)
For j = 0 To UBound(arr, 2)
If IsObject(arr(i, j)) Then
Set arr(i, j) = Nothing
Else
arr(i, j) = Empty
End If
Next
Next
End Sub
或者像这样,如果您不想将包含对象的字段设置为Nothing
:
Or like this, if you don't want to set fields containing objects to Nothing
:
Sub EraseArray(ByRef arr)
For i = 0 To UBound(arr, 1)
For j = 0 To UBound(arr, 2)
arr(i, j) = Empty
Next
Next
End Sub
这篇关于如何清除vbscript中数组的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!