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

Concatenate a for loop

Status
Not open for further replies.

woter324

Technical User
Jan 26, 2007
179
GB
Hi,

Would anybody be able to tell me how to concatenate the contents of a for loop together adding each return value to the last. For example I have a string
Code:
cInsDir = "C:\fldr1\fldr2\fldr3"
I use split(cInsDir, "\") to break it down. I need the output to be:
C:\fldr1
C:\fldr1\fldr2
C:\fldr1\fldr2\fldr3 etc...

The code below returns:
C:
fldr1
fldr2
fldr3

Code:
Set dict = CreateObject("Scripting.Dictionary")
Dim aryW, i, str, k
aryW = Split(cInsDir,"\")
k = 1

For i = 0 To UBound(aryW)
	str = aryW(i)
		k = k +1
		dict.Add k, str 
		MsgBox dict.Item(k)
Next

Perhaps I should be using a while loop instead of a for loop??

At this point, the path doesn't actually exist so I can't use fileSystemObject methods and as this script sets a file on a server, the script doesn't have access to the client.

TIA

Woter
 
[tt]str = ""
For i = 0 To UBound(aryW)
str=str & aryW(i) & "\"
dict.Add k, str
MsgBox dict.Item(k)
k=k+1
Next[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top