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

Array help 1

Status
Not open for further replies.

rabisco

MIS
Jan 4, 2007
21
I'm really hoping some kind soul can help here.

THis code...

for each item in arrExcel

if item <> "None" then
Response.Write item
Response.Write("<br>")
End if
Next


Gets the item I want an print it out.

I would like to get the index of the item in the array arrExcel. How would I do that.

The arrExcel is populated thus.....

For Each keyb In Request.Form
If Left(keyb, 15)="excelFieldName_" Then
'Response.Write(Request.Form(keyb) & "<br />")
ReDim Preserve arrExcel(myCounterb)
arrExcel(myCounterb) = Request.Form(keyb)

myCounterb = myCounterb+1
End If
Next

Any help would be appreciated.
 
Try this: it may give you what you want
Code:
ix = 0
for each item in arrExcel
    
        if item <> "None" then
            Response.Write cstr(ix) & item 
            Response.Write("<br>")
        End if
    ix = ix + 1
Next
 
I have an add on question to the issue you resolved yesterday..

I am using these two routines to get the index of certain items in an array

ide = 0
for each item in arrExcel
if item <> "None" then
Response.Write cstr(ide) '& item
Response.Write("<br>")
End if
ide = ide + 1
Next

Lets assume that I get the indexes 2 and 5 written out, I then need to do the following.

1. store the index values,
2. search another array for the same index values i.e. 2 and 5
3. Get the values of the indexes.

Thanks
 
There isn't any magic formula for this. What you think how to do is what the script reflects. (There is no guarantee that you'll find it though, nor, if found, unique.)
[tt]
dim a()
redim a(-1)
ide = 0
for each item in arrExcel
if item <> "None" then
Response.Write cstr(ide) '& item
Response.Write("<br>")
redim preserve a(ubound(a)+1)
a(ubound(a))=ide
End if
ide = ide + 1
Next

for each idx in a
ide=0
'second array arrExcel2
for each item in arrExcel2
if item=idx then
Response.Write "(" & cstr(ide) & "," & cstr(idx) & ")"
Response.Write("<br />")
end if
ide=ide+1
next
next
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top