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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic array variable 1

Status
Not open for further replies.

JadeKnight

IS-IT--Management
Feb 23, 2004
94
NO
I'm having a bit of a trouble getting some data into an arryay. The problem is the array arrTmp wich I would like to be a dynamic array. I've tried to declare it with just Dim arrTmp, but that gives me an error. If I declare it with a fixed subscript, like the code below. It works fine, but this will not work if I don't know how many entires there will be in object.

Code:
Sub EnumToString(OBJECT,STRINGNAME)

	Dim i,x,arrTmp(50)
	x = -1
	'On Error Resume Next
	
	For i = 0 to OBJECT.Count - 1 Step 2
		x = x + 1

		arrTmp(x) = OBJECT.Item(i)
		
	Next

	
	STRINGNAME = Join(arrTmp)
	
	wscript.echo STRINGNAME

End Sub

I've tried a couple of ReDim statements in the loop with no futher succsess... Any help would be appreciated.

Tia :)
JadeKnight
 
Something like this ?
Sub EnumToString(OBJECT,STRINGNAME)
Dim i,x,arrTmp()
x = -1
'On Error Resume Next
For i = 0 to OBJECT.Count - 1 Step 2
x = x + 1
ReDim Preserve arrTmp(x)
arrTmp(x) = OBJECT.Item(i)
Next
STRINGNAME = Join(arrTmp)
wscript.echo STRINGNAME
End Sub

Another way without array:
Sub EnumToString(OBJECT,STRINGNAME)
Dim i
STRINGNAME=""
For i = 0 To OBJECT.Count - 1 Step 2
STRINGNAME = STRINGNAME & " " & OBJECT.Item(i)
Next
STRINGNAME = Mid(STRINGNAME,2)
WScript.Echo STRINGNAME
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top