Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 19th, 2006, 05:36 PM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default CSV File to Array Problems with Comma in Field

I am trying to help out a friend with a much easier way to post his tabular data. He usually receives an Excel file containing all the data. I have used some ASP to simply parse through the text file, format and display the results. My problem comes when I have a field that contains a comma (like "LASTNAME, FIRSTNAME"). My script is actually putting the last name and first name in 2 separate fields as well as displaying the commas. Any help would be appreciated. I hope this isn't too confusing...I'm not terribly skilled with ASP.

<%

'Code to display data from the current text-based logfile
Dim objFSO, oInStream, sLine, sSeg

'Define the constants used by the FSO
Const Forreading = 1

'Create an instance of the FSO
Set objFSO = CreateObject("Scripting.fileSystemObject")

'Check the file exists
If objFSO.fileExists( Server.MapPath( "alpha.csv" ) ) Then
  'open a file for reading
  Set oInStream = objFSO.openTextfile( Server.MapPath( "alpha.csv" ), Forreading, False )
  sLine = oInStream.readLine
  sSeg = Split( sLine, "," )
%>

<TABLE width="100%" cellpadding="2" cellspacing="0" border="0">
  <TR class="headerrow">
  <% for loopctr = 0 to ubound(sSeg)
       if loopctr > 0 then response.write("<TD width='10' nowrap>&nbsp;</TD>")
       response.write ("<TD nowrap>" & sSeg(loopctr) & "</TD>")
     next
  %>
  </TR>

<%
myRow=2
Do Until oInStream.AtEndOfStream
sLine = oInStream.readLine
sSeg = Split( sLine, "," )
if sSeg(0)="" then
  else
  if myRow=2 then
     myRow=1
   else
     myRow=2
   end if
end if
%>
  <TR class="bodycopy">
    <% for loopctr = 0 to ubound(sSeg)
         if loopctr > 0 then response.write("<TD width='10' nowrap class='tablerow" & myRow & "'>&nbsp;</TD>")
     response.write ("<TD nowrap class='tablerow" & myRow & "'>" & sSeg(loopctr) & "</TD>")
      next
%>
  </TR>
<%
loop
%>
</TABLE>
<%
oInStream.Close
Set oInStream = Nothing
else
response.write("Sorry. Information for this event has not been posted. Please check back later.")
 end if %>
  #2 (permalink)  
Old July 19th, 2006, 05:58 PM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I came up with a better solution...instead of splitting on the comma, I saved out a tab-delimited file and split on that instead. Works fine. Thoughts?


Similar Threads
Thread Thread Starter Forum Replies Last Post
populating a listbox with a field contains comma bjcountry Access 3 February 17th, 2016 05:07 PM
CSV > XML (converting problems) Kabe XML 6 November 17th, 2008 09:46 AM
Exporting a csv file (comma separated) micharl Beginning VB 6 6 May 7th, 2008 10:10 PM
Inserting comma in the field issaq SQL Language 0 February 20th, 2008 08:41 AM
inverted comma problems in ASP response.write paulmcn Classic ASP Basics 2 September 16th, 2005 04:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.