Solved

Array from loop

Posted on 2013-01-15
2
248 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

15 Experts available now in Live!

Get 1:1 Help Now