separating arrays...

1. Senior Member
Join Date
Dec 1969
Posts
175

## separating arrays...

I have a request field which responses<BR>6312&12, 6312&34, 7534&23, 7656&17, ...<BR>I want to separate them in two arrays<BR>First one...<BR>6312<BR>6312<BR>7534<BR>7656<BR>..<BR><B R>Second one...<BR>12<BR>34<BR>23<BR>17<BR>... <BR>Can some one help me with this code<BR><BR>Thanx

2. Senior Member
Join Date
Dec 1969
Posts
5,104

## Split() and then it get's ugly...

You can use Split() to create the first array.. but, you are going to need to loop through the array and break the value down.<BR><BR>Dim aList<BR> aList = Split("6312&12, 6312&34, 7534&23, 7656&17", ",")<BR>Dim iCnt<BR> For iCnt = 0 To UBound(aList, 1)<BR> aList(iCnt) = Split(aList(iCnt), "&")<BR> Next<BR><BR>That will give you an array that contains arrays. To use it, you would have to do:<BR>Response.Write "First Part, 0: " & aList(0)(0) & "&#060;br /&#062;"<BR>Response.Write "Second Part, 0: " & aList(0)(1) & "&#060;br /&#062;"<BR><BR>To view them all, you would use a loop similar to the one you used to break them down:<BR> For iCnt = 0 To UBound(aList, 1)<BR> Response.Write "First Part, " & iCnt & ": " & aList(iCnt)(0) & "&#060;br/ &#062;"<BR> Response.Write "Second Part, " & iCnt & ": " & aList(iCnt)(1) & "&#060;br/ &#062;"<BR> Next<BR><BR>-Doug

3. Senior Member
Join Date
Dec 1969
Posts
175

## Thanx but Error

I am getting this error<BR>Error Type:<BR>Microsoft VBScript runtime (0x800A000D)<BR>Type mismatch: &#039;6320&#039;<BR>/nashlaptop/remcode.asp, line 62<BR><BR>For i = 0 To ubound(thecr)<BR>Response.Write "First Part, " & i & ": " & thecr(i)(0) & "&#060;br/&#062;" Response.Write "Second Part, " & i & ": " & thecr(i)(1) & "&#060;br/&#062;" &#039;line 62<BR>Next<BR><BR>The complete code is<BR>dim theid, thecr<BR>theid = split(Request("id"), ",")<BR>for i = 0 to ubound(theid)<BR>thecr = split(theid(i), "&")<BR>next<BR><BR>For i = 0 To ubound(thecr)<BR>Response.Write "First Part, " & i & ": " & thecr(i)(0) & "&#060;br/&#062;" Response.Write "Second Part, " & i & ": " & thecr(i)(1) & "&#060;br/&#062;" &#039;line 62<BR>Next<BR><BR>Thanx<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
5,104

dim theid, thecr<BR>theid = split(Request("id"), ",")<BR>for i = 0 to ubound(theid)<BR>theid(i) = split(theid(i), "&") ** this line<BR>next<BR><BR>Then, you need to change the displaying look to use theid instead of the thecr.<BR><BR>-Doug

5. Senior Member
Join Date
Dec 1969
Posts
2,493

## RE: Thanx but Error

Keep it simple<BR><BR>&#060;%<BR>&#039;The complete code is <BR><BR>dim theid, thecr <BR>theid = split(id, ",") <BR>for i = 0 to ubound(theid) <BR>thecr = split(theid(i), "&") <BR>next <BR><BR>For i = 0 to ubound(theid) <BR> thecr = split(theid(i), "&") <BR> Response.Write "First Part, " & i & ": " & thecr(0) & "&#060;br/&#062;" <BR> Response.Write "Second Part, " & i & ": " & thecr(1) & "&#060;br/&#062;"<BR>Next <BR>%&#062;

6. Senior Member
Join Date
Dec 1969
Posts
2,493

## RE: Thanx but Error

Keep it simple<BR><BR>&#060;%<BR>&#039;The complete code is <BR><BR>dim theid, thecr <BR>theid = split(id, ",") <BR><BR>For i = 0 to ubound(theid) <BR> thecr = split(theid(i), "&") <BR> Response.Write "First Part, " & i & ": " & thecr(0) & "&#060;br/&#062;" <BR> Response.Write "Second Part, " & i & ": " & thecr(1) & "&#060;br/&#062;"<BR>Next <BR>%&#062;

7. Senior Member
Join Date
Dec 1969
Posts
2,493

## ignore first post click the button to soon <e

.

8. Senior Member
Join Date
Dec 1969
Posts
5,104

## Good point, but...

In the original post, he said:<BR>&#062;I want to separate them in two arrays <BR><BR>I got the feeling that he wanted to put them into 2 arrays at one point in the page and then use them in a different part.<BR><BR>Oh, well. Two ways to skin the cat...<BR><BR>-Doug

9. Senior Member
Join Date
Dec 1969
Posts
2,493

## RE: Good point, but...

So did I until I saw his code and the way he was writing out the values. <BR><BR>In that case how about this<BR><BR>Dim SecondArray() <BR>FirstArray = Split(id,",")<BR>ReDim SecondArray(Ubound(FirstArray))<BR>for i = 0 to Ubound(firstarray)<BR> TmpArray=Split(FirstArray(i),"&")<BR> FirstArray(i)= TmpArray(0)<BR> SecondArray(i) = TmpArray(1)<BR>next<BR><BR><BR>For i = 0 to ubound(FirstArray) <BR> Response.Write "First Part, " & i & ": " & FirstArray(i) & "<BR>" <BR> Response.Write "Second Part, " & i & ": " & SecondArray(i) & "<BR>" <BR>Next <BR>

10. Senior Member
Join Date
Dec 1969
Posts
175

## Thanx Doug... I got it running <eop>

.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•