Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the contents of an array in vbscript?

Tags:

vbscript

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)

In action1,

erase strVerifyAry

Error message

Run Error - Type mismatch: 'Erase'

How to clear the contents of this array?

like image 893
Saranya Avatar asked Jun 05 '13 09:06

Saranya


1 Answers

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

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
like image 110
Ansgar Wiechers Avatar answered Sep 24 '22 17:09

Ansgar Wiechers