[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Array from loop

Posted on 2013-01-15
2
Medium Priority
?
259 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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