View Full Version : loop question?
Rino5555
05-13-2008, 08:21 PM
Hi to all...
I have this code that will combine 2 pdf to one in dest.pdf...
Which works fine...
dim C
Set C=CreateObject("Combine.Combine")
C.Convert "c:\1.pdf"+Chr(13)+"c:\2.pdf", "c:\dest.pdf", ""
set C = nothing
What i would like to do is with check boxes i would select the pdf i want and it will combine them...
How would i do a loop in the command line that would add the file name if there are 2, 4 or 8...
Or is it a loop that i need...
Please help...
Thanking you in advance...
Rino
dsagrera
05-14-2008, 01:57 PM
I would do a form in the previous screen with all the possible PDF files to be included, make one checkbox for each PDF available, and name it with the same name, let's say "pdf", but the value of each one would be the name of the file, example:
<body>
<form name="form1">
<input type="checkbox" name="pdfs" value="c:\file1.pdf">This is PDF 1<br>
<input type="checkbox" name="pdfs" value="c:\file2.pdf">This is PDF 2<br>
<input type="checkbox" name="pdfs" value="c:\file3.pdf">This is PDF 3<br>
<input type="checkbox" name="pdfs" value="c:\file4.pdf">This is PDF 4<br>
<input type="checkbox" name="pdfs" value="c:\file5.pdf">This is PDF 5
</form>
</body>
What browsers do is join, sepparated by commas every form element with the same name, so the POST of this form to the next page, which would be your ASP code will get from the "pdfs" checkbox is "c:\file1.pdf, c:\file2.pdf, c:\file3.pdf, c:\file4.pdf, c:\file5.pdf"
Now, before the Convert thing, you simply have to split (with the split function) the entire string into small strings sepparated by commas. The only LOOP you have to do now is a FOR / NEXT, getting every filename, one by one, example:
filenames = Split(Request.Form("pdfs"), ",")
maxfiles = Ubound(filenames)
For thisfile = 0 to maxfiles
totalfiles = filenames(thisfile) & Chr(13)
Next
Set C=CreateObject("Combine.Combine")
C.Convert totalfiles, "c:\dest.pdf", ""
Maybe the code needs a little fix, I don't know how the Combine component works at all! Let me know if it works. Regards! Diego.
Rino5555
05-14-2008, 03:19 PM
Looks like this will help...
I'll try it and let you know...
Thanks Rino
Rino5555
05-14-2008, 03:44 PM
I tried it and it worked fine...
I went to my c:\ drive and found the dest.pdf with the ones i selected...
just that in my second .asp page where i point to and where it does the loop...
i put the a href line
<A HREF="c:\dest.pdf"><img border="0" height="32" width="33" SRC="/Images/pdf.gif"></A>
but when i mouse over it becomes clickable but nothing happenes...
would you know why...
thanking you in advance...
Rino
dsagrera
05-15-2008, 12:22 AM
Try something like this in the ASP part:
Response.Write("<A HREF='" & Server.MapPath("c:\dest.pdf") & "'><img border='0' height='32' width='33' SRC='/Images/pdf.gif'></A>")
Let me know! Regards. Diego.
Rino5555
05-15-2008, 03:15 PM
I didn't try eyt your response because the merge is not working...
Can you see if the loop is correct...
TestSample.asp
<form action="TestSample2.asp" method="post" name="form" >
<INPUT TYPE=CHECKBOX name="pdfs" value="c:\1.pdf"> pdf 1<BR>
<INPUT TYPE=CHECKBOX name="pdfs" value="c:\2.pdf"> pdf 2<BR>
<INPUT TYPE=CHECKBOX name="pdfs" value="c:\3.pdf"> pdf 3<BR>
<INPUT TYPE=CHECKBOX name="pdfs" value="c:\4.pdf"> pdf 4<BR>
<input type="Submit" Value="Submit" STYLE="color:#000000">
</form>
in TestSample2.asp page
filenames = Split(Request.Form("pdfs"), ",")
maxfiles = Ubound(filenames)
For thisfile = 0 to maxfiles
totalfiles = filenames(thisfile) & Chr(13)
Next
Set C=CreateObject("PDFCombine.PDFCombineX")
sC.Convert totalfiles, "c:\dest.pdf", ""
If i select one it works and the files gets created, if i select 2 or more it doesn't work....
dsagrera
05-15-2008, 11:31 PM
Try replacing the SPLIT line from:
filenames = Split(Request.Form("pdfs"), ",")
to:
filenames = Split(Trim(Request.Form("pdfs")), ",")
or to:
filenames = Split(Request.Form("pdfs"), ", ")
Rino5555
05-16-2008, 05:59 PM
i found the problem...
totalfiles only had one file name because in my line i was overwriting everytime it came in
totalfiles = filenames(thisfile) & Chr(13)
it should be like this...
totalfiles = totalfiles & "+" & filenames(thisfile)
now its working... thank you...
Does anyone know if there a right way to end a loop command...
because i'm getting a microsoft debug error "COM Surrogate"
i searched for it and they say it can be an infinite loop in an ASP page...
here's my loop
For thisfile = 0 to maxfiles
If thisfile = 0 then
totalfiles = filenames(thisfile)
Else
totalfiles = totalfiles & "+" & filenames(thisfile)
End if
Next
pqrs055
05-17-2008, 10:20 AM
As it is known to all, we often follow these ways when we are building the weight loss (http://loseweight.kmdali.com/) plan : exercises , slimming pills (http://loseweight.kmdali.com/chphp/slimmingproduct.php), diet therapy, slimming machine ( eg. High-frequency vibration belly fat removing instrument), acupuncture treatment , healthy diet , reducing alcohol take-in, and herbal weight loss . Unfortunately , few of them are effective and no rebound .
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.