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!

looping through one record where separated by commas. 1

Status
Not open for further replies.

timtom

Programmer
Jul 12, 2001
78
GB
Hello. Is there any way I can do this?

Users have the choice of printing out a particular letter to any number or combination of around 50 individuals. They select who they want to send to from a list and this enters the codes for all the people into a table - along with the code of the particular letter they are to send. The data in the SQL table looks like this :

LETTERID SEND_TO
34 sfd231, 13342nkj, 25knlnl, 345trkml, etet343
67 fdsf44, 453mfmsd, 5klmlk4

etc.

But when I come to prepare the letters (with correct addresses etc.) I'm not sure how loop it. I am used to using movenext and while not eof but not sure if I can loop within a particular record. Is there anyway I can make the page loop through all the codes separated by commas? If not, I am open to redesigning the table if anyone can help? Thankyou much
Sarah :)
 
What you could do is split the SEND_TO field using the comma. Something like the following would work ( assume that you have created a recordset called "record" containing the two records you included in your post)

do while not record.EOF
letter = record.Fields("LETTERID")
send_to = split(record.Fields("SEND_TO"), ",")

for i = 0 to Ubound(send_to)
' Enter code here to send letter to send_to(i)
next

record.MoveNext
loop

Something like that should solve your problem.
Mise Le Meas,

Mighty :)
 
dont worry.nothing is impossible.
think on another way
cull out the particular record and stored into a string
and then findout howmany commas "," in that string

here i gave a code for seperating a each code from the string try by paste this on new asp page and check by changing the value of "a"


---------------
<%
dim a,count,pnt
dim myarr(10)
dim posar(10)

count=1'to fine how many commas
myarr(0)=0 'for starting pos of stud id
pnt=1 'pointer var
posar(0)=0 'for the length of each stud id

'cull out the string from the database and store it in a string
a=&quot;sfd231,13342nkj,25knlnl,345trkml,etet343&quot;


for i = 1 to len(a)
if mid(a,i,1)=&quot;,&quot; then
count=count+1 'increment for no. of words
myarr(pnt)=i 'staring pos
posar(pnt)=myarr(pnt)-myarr(pnt-1) 'length of string
pnt=pnt+1 'increment the array index
end if
next

Response.Write(a+&quot;<br>&quot;)'print the given string
Response.Write(count) 'no of words
Response.Write(&quot;<br><br>&quot;)

' this thing is because of we are searching and seperating by commas
' we dont have the comma on the end of the string so
myarr(pnt)=len(a)'virtually put comma on the end of the string
posar(pnt)=len(a)-myarr(pnt-1)'length of the last string

'print the each string seperately
for i=1 to count
Response.Write(mid(a,myarr(i-1)+1,posar(i)-1)+&quot;<br>&quot;)
next

%>
-----------------

with regards
raghu
all the best
 
timtom,

I just had a look at the suggestion I gave you and if you are not familiar with the Split command, it is not very clear.

the split command uses a separator ( in this case a comma ) to split a string up into an array of smaller strings.

thus,

send_to = split(record.Fields(&quot;SEND_TO&quot;), &quot;,&quot;)

would result in an array like:

send_to(0) = sfd231
send_to(1) = 13342nkj

and so on.

So once you use the split command, you just need to loop through the send_to array to send the letter to each element of the array. Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top