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!

Arrays 1

Status
Not open for further replies.

bigairguy

Programmer
May 10, 2005
14
US
Hey guys-

I was hoping you could help me with two extremely simple arrays, as I am not very good with them. I am using VBScript in an ASP page. Basically, I have two arrays, one in which output is created based only on array elements that aren't null or 0. I have a second array in which I want to place the corresponding title in front of the the output placed by the first array. What I need to do is equate the indexes so that I'm printing the two elements of data with the same index in each array, but I can't figure out how to retrieve the index. Here is an example of some of my code:

Dim TitleArray(3)
Dim DataArray(3)

Dim NumColumns
Dim NumColMax

TitleArray(0) = "First Name: "
TitleArray(1) = "Reserved: "
TitleArray(2) = "Last Name: "

DataArray(0) = Request.Querystring("FirstName")
DataArray(1) = Request.Querystring("Reserved")
DataArray(2) = Request.Querystring("LastName")

NumColumns = 0
NumColMax = 2

For Each Elem in DataArray
If Elem <> "" And Elem <> "0" Then
If NumColumns < NumColMax Then
Response.Write "<td>" & TitleArray(Elem) & Elem & "</td>"
NumColumns = NumColumns + 1
Else
Response.Write "</tr><tr><td>" & TitleArray(Elem) & Elem & "</td>"
NumColumns = 1
End If
End If
Next

The bold is the part that's wrong, but I can't figure out how to put the DataArray index value of each iteration into TitleArray to retrieve the proper corresponding element of TitleArray.

I'm figuring this is a simple problem. If you need more code, let me know.

Thanks in advance,
Patrick
 
[tt] For Elem=0 to ubound(DataArray)
If DataArray(Elem) <> "" And DataArray(Elem) <> "0" Then
If NumColumns < NumColMax Then
Response.Write "<td>" & TitleArray(Elem) & DataArray(Elem) & "</td>"
NumColumns = NumColumns + 1
Else
Response.Write "</tr><tr><td>" & TitleArray(Elem) & DataArray(Elem) & "</td>"
NumColumns = 1
End If
End If
Next
[/tt]
 
Thanks, tsuji! That's exactly what I was trying to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top