?
Solved

Array from loop

Posted on 2013-01-15
2
Medium Priority
?
257 Views
Last Modified: 2013-01-15
Hi!
I have a simple problem with arrays.

I want to build an array of a loop, then i want to store the result in a variable.

I have a loop like this:

while not rsSpare.eof
response.write rsSpare("SupportProcessSparepart")&""
rsSpare.movenext
wend

And if there is more than one sparepart then i want to seperate them with an break and then i want to store this in a variable named spareparts and the output will be:

sparepart1
sparepart2
...

I will use the variable in an mailcomponent. Can you help me, i know that this is basic, but i am in a hurry and i am really bad at arrays :-)
0
Comment
Question by:MickeC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 38778476
you would do like this:

Dim spare_parts
spare_parts = ""

while not rsSpare.eof
  spare_parts = spare_parts & rsSpare("SupportProcessSparepart")&"<br>"
  rsSpare.movenext
wend

response.write spare_parts 

Open in new window


you can replace the "<br>" by whatever you mail component will need as "break".
this is a non-array solution...
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 38778544
Here is how you create an array of N size, adding to it as you loop through your object.
In this example, I merely loop through the numbers 1 through 10.
<%
Dim arrSpareParts() 
Dim i 
i=0

While i < 10
	Redim Preserve arrSpareParts(i)
	arrSpareParts(i) = "Value_" & i
	i = i + 1
Wend

For Each item In arrSpareParts
	Response.Write(item & "<br />")
Next
%>

Open in new window


Using your rsSpare object, it would look like this:
<%

Dim arrSpareParts() 
Dim i 

i=0

while not rsSpare.eof
	Redim Preserve arrSpareParts(i)
	arrSpareParts(i) = rsSpare("SupportProcessSparepart")
	i = i + 1
	rsSpare.movenext
wend

For Each item In arrSpareParts
	Response.Write(item & "<br />")
Next
%>

Open in new window


A little bit cleaner, but I'm not sure if I have the syntax correct for rsSpare.Index, would be something like this (not sure if the first value is 0 or 1 - if it is 1, then you will want to subtract 1 from it so that the first item in your array is number 0:
<%

Dim arrSpareParts() 
Dim i 

while not rsSpare.eof
	i = rsSpare.Index
	Redim Preserve arrSpareParts(i)
	arrSpareParts(i) = rsSpare("SupportProcessSparepart")
	rsSpare.movenext
wend

For Each item In arrSpareParts
	Response.Write(item & "<br />")
Next
%>

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question