Solved

Array from loop

Posted on 2013-01-15
2
250 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
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now