?
Solved

Using multiple in select creates spaces??

Posted on 2012-08-13
13
Medium Priority
?
372 Views
Last Modified: 2012-08-13
I am trying to attach files to an email by allowing a user to select file(s) from a select ojbect and it keeps adding a space between the file path and any files attached after the first.  Confusing?  Here is what I am using to get the file:

<select name="file_links" id="file_links" multiple>
	<%For i = 0 to UBound(FileArr) - 1%>
		<option value="<%=FileArr(i)%>"><%=FileArr(i)%></option>
	<%Next%>
</select>

Open in new window


Here is how I am breaking the string up:
	Dim sFiles
	Dim Files()
	
	sFiles = Request.Form.Item("file_links")

	j = 0
	ReDim Files(0)
	For i = 1 To Len(sFiles)
		If Mid(sFiles, i, 1) = "," Then
			Files(j) = CStr(Files(j))
			j = j + 1
			ReDim Preserve Files(j)
		Else
			Files(j) = Files(j) & Mid(sFiles, i, 1)
		End If
	Next

Open in new window


Here is my attachment code:
	If UBound(Files) > 0 Then
		For i = 0 To UBound(Files)
			.AddAttachment "c:\inetpub\h51web\etraxc\file_fldr\files\" & Files(i)
		Next
	End If

Open in new window


And here is the problem:
c:\inetpub\h51web\etraxc\file_fldr\files\CustomBlackBeltsOrderForm.xls
c:\inetpub\h51web\etraxc\file_fldr\files\ rprt_card_code.doc
c:\inetpub\h51web\etraxc\file_fldr\files\ Tortellini Soup.doc

(note the spaces between the file path and the file name in all but the first file..
0
Comment
Question by:Bob Schneider
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 15

Assisted Solution

by:pateljitu
pateljitu earned 572 total points
ID: 38288245
Please try this code:

Dim sFiles
	Dim Files()
	
	sFiles = Request.Form.Item("file_links")

	j = 0
	ReDim Files(0)
	For i = 1 To Len(sFiles)
		If Mid(sFiles, i, 1) = "," Then
			Files(j) = CStr(Trim(Files(j)))
			j = j + 1
			ReDim Preserve Files(j)
		Else
			Files(j) = Files(j) & Mid(Trim(sFiles), i, 1)
		End If
	Next

Open in new window

0
 
LVL 5

Assisted Solution

by:mvdeveloper
mvdeveloper earned 288 total points
ID: 38288277
What happens if you have a simple:

Files = Split(sFiles,",")
0
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 1140 total points
ID: 38288279
may I suggest another way to put the list of files into an array? I would use the Split() function. it'll take a string and split it into an array based upon the specified delimeter:

Dim sFiles
Dim Files()
	
sFiles = Request.Form.Item("file_links")
Files = Split( sFiles, "," )

Open in new window


when passing multiple values from a single select box a comma will be used to seperate the values. my guess is an extra space was being added in your loop, and thats why it was appearing in the file path
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Bob Schneider
ID: 38288411
pateljitu, I tried that.  It takes any spaces out of the file name if there are some and then doesn't locate the file.

I will try the Split approach and see what happens...
0
 

Author Comment

by:Bob Schneider
ID: 38288435
Got a type mismatch on the last line:


      Dim sFiles
      Dim Files()
      
      sFiles = Request.Form.Item("file_links")
      Files = Split(sFiles, "," )
0
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 1140 total points
ID: 38288445
Try removing

Dim Files()
0
 
LVL 15

Assisted Solution

by:pateljitu
pateljitu earned 572 total points
ID: 38288446
Also in case you only want to remove trailing spaces from left of string, please try LTRIM() instead of TRIM() function.

For e.g. Files(j) = CStr(LTrim(Files(j)))
0
 

Author Comment

by:Bob Schneider
ID: 38288578
I removed Dim FIles() and it threw an error so I re-added Dim Files and the email sent but without an attachment.  I tried the LTrim thing earlier and to no avail.  This really has me puzzled...
0
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 1140 total points
ID: 38288751
can you post the code you're now using?
0
 

Author Comment

by:Bob Schneider
ID: 38288907
Dim sFiles
      Dim Files
            
      sFiles = Request.Form.Item("file_links")
      Files = Split(sFiles, "," )

Note that I tried it without the "Dim Files" and with "Dim Files()".  The first did not attach anything (I think) and the second generated a type mismatch error.
0
 
LVL 34

Accepted Solution

by:
Big Monty earned 1140 total points
ID: 38288923
try putting this right after the code segment above:

for each fileName in Files
   Response.Write "File: " & fileName & "<br/>"
next

does anything get written out to the screen?
0
 

Author Comment

by:Bob Schneider
ID: 38288957
Got it figured out...added a space after the comma in Split(sFiles, ",") so that it is now Split(sFiles, ", ")

Thanks all for the help
0
 

Author Closing Comment

by:Bob Schneider
ID: 38288965
Great assistance!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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/…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

850 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