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!

Help with for..next logic

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I am trying to concatenate these variables (col1 thru col15) using for ..next loop, without success.
Any help will be greatly appreciated. Thanks

scontent= ""
intMonth = 10

col1 = "Budget"
col2 = "gap"
Col3 = "blue jeans"
col4 = "100"
col5= "101"
col6= "102"
col7= "103"
col8= "101"
col9= "102"
col10= "105"
col11= "102"
col12= "102"
col13= "102"
col14= "102"
col15= "102"

for i = 1 to (intMonth + 3)
if ((intMonth + 3) = 4 or i = intMonth + 3) then
scontent = scontent & col & i & vbCrLf
else
scontent = scontent & col & i & ","
end if
'wscript.echo (scontent)
next
 
For starters, you can make your life easier by using an array.

Code:
scontent= ""
intMonth = 10
dim col(15)

col(1) = "Budget"
col(2) = "gap"
col(3) = "blue jeans"
col(4) = "100"
col(5) = "101"
col(6) = "102"
col(7) = "103"
col(8) = "101"
col(9) = "102"
col(10) = "105"
col(11) = "102"
col(12) = "102"
col(13) = "102"
col(14) = "102"
col(15) = "102"

for i = 1 to (intMonth + 3)
if ((intMonth + 3) = 4 or i = intMonth + 3) then
scontent = scontent & col(i) & vbCrLf
else
scontent = scontent & col(i) & ","
end if
'wscript.echo (scontent)
next
 
Another way is to use the Eval function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What is your file source? Is this just a text tile, or is this Excel or somethng else? Where is the col data coming from?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thank you very much for the very quick response. Re-wrote my code per your sample and it's working like a charm.
Thanks again.
 
PHV, I also tried your solution and it worked as well. Good to know there are different options.

SkipVought, I am reading it off a tab-delimited file.

Thanks again, all!!!!
 
Actually, if you have an array it is possibly even easier than that ...

Code:
[blue]scontent = ""
intMonth = 1
Dim col()
ReDim col(15)

' Populate array from wherever. In this case we do it manually
col(0) = "Budget"
col(1) = "gap"
col(2) = "blue jeans"
col(3) = "100"
col(4) = "101"
col(5) = "102"
col(6) = "103"
col(7) = "101"
col(8) = "102"
col(9) = "105"
col(10) = "102"
col(11) = "102"
col(12) = "102"
col(13) = "102"
col(14) = "102"

ReDim Preserve col(intMonth + 2) ' remember we start at 0, not 1
If intMonth = 1 Then Joiner = vbCrLf Else Joiner = ". " ' Handle oddity if intMonth = 1
scontent = Join(col, Joiner) & vbCrLf[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top