Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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 %>
Reply With Quote
  #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?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.