Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign value of array1 to array 2

Status
Not open for further replies.

cerruti1881

Technical User
Nov 8, 2012
10
AU
I wrote the following testing code:

Code:
Dim array1(6)
Dim array2()

array1(0) = "a"
array1(1) = "b"
array1(3) = ""
array1(4) = "c"
array1(5) = ""
array1(6) = "d"

For i = 0 to 6
   If array1(i) <> "" Then
      array2(i)= array1(i)
   End If
Next

For i = 0 to Ubound(array2)
   If array2(i) <> "" Then
      Wscript.Echo array2(i)
   End If
Next

The above script gives error:
Microsoft VBScript runtime error: Subscript out of range

Anyone knows how to assign value of array 1 to array 2 if conditions are met?
 
Simple answer is
Code:
Dim array2([highlight #FCE94F]6[/highlight])

Also look into the ReDim command
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top