title: How do I declare global array in VBScript
body: <p>I'm trying to store an array value so that I can reuse when Sub is called more than once.
  I would like to prevent from reassigning values to the array if value exist.</p>
  
  <p>My code is something like this.</p>
  
  <pre><code>Dim views()
  
  Sub runit()
      For i=0 To 3
          test()
      Next    
  End Sub
  
  Sub test()
          ReDim Preserve views(0)= "test"
  
         ' - other codes that I want to run-
  End Sub
  </code></pre>
  
  <p>I get " Type mismatch :'choseviews'" error.</p>
  
  <p>If I move "Dim views()" inside "Sub test", I don't get the error.
  How do I declare global array in VBScript?
  If it's not possible, is there any ways to prevent reassigning array when Sub is called?</p>
  
  <p>This following code does not work but you may get an idea what I'm trying to do .</p>
  
  <pre><code>    Dim views()
  
      Sub runit()
          For i=0 To 3
              test()
          Next    
      End Sub
  
      Function IsArrayDimmed(arr)
         IsArrayDimmed = False
         If IsArray(arr) Then
           On Error Resume Next
           Dim ub : ub = UBound(arr)
           If (Err.Number = 0) And (ub &gt;= 0) Then IsArrayDimmed = True
          End If  
       End Function
  
  
      Sub test()
          If IsArrayDimmed(views) Then
  
          Else
               ReDim Preserve views(0)= "test"
  
          End If
                 ' - other codes that I want to run-
      End Sub
  </code></pre>
  
  <p>Thank you for your help.</p>