Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Reading and grabing data from a txt file
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Reading and grabing data from a txt file

 Post Reply Post Reply Page  <12
Author
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 05 June 2004 at 5:02am
Howcome you arn't using XML for this? It will be quite hard to do what you are trying to do and most likely pointless if you could do it with XML
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 05 June 2004 at 12:59pm
I can't use xml. The text file is exported by an Access application, and I have to deal with it. Also, the best way to something is the way you know it. I never use xml, so I never though of it as a possible solution.
Cristian Banu
Soft 4 web
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 06 June 2004 at 5:00pm
Ok, i have tryed to put the rows in an array, then use the Split(Rowarray(i), "[section]") to get the rows in a section, then put them in an array to get the fields, nut with no luck. Any hints?
Cristian Banu
Soft 4 web
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 07 June 2004 at 10:03am
Well, it seems there is no need for arrays... I have sorted it partially. I have put there only the response.write to simplify.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="connect.asp"-->
<%
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set theTextFile = FSO.OpenTextFile("E:\webs\ranbaxyromania.ro\wwwroot\files\tb lViziteDoctori1.txt")
While Not theTextFile.AtEndOfStream
theTextLine=theTextFile.ReadLine
If theTextline = "[section 1]" then
do
theTextLine=theTextFile.ReadLine
response.Write theTextLine & "<br>"
loop Until theTextLine = "[section 2]"
End if
If theTextline = "[section 2]" then
do
theTextLine=theTextFile.ReadLine
response.write theTextLine & "<br>"
loop Until theTextLine = "[section 3]"
End if
Wend

' Close up to be tidy

theTextFile.Close
Set theTextFile = Nothing

MyConn.Close
Set MyConn = Nothing
%>

The problem is that it lists also the section delimeter, and this crushes the insert. How can I skip this line?
Cristian Banu
Soft 4 web
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 07 June 2004 at 1:28pm

If you're referring to the End-Of-Section delimiter, try changing the loop until the end of the section rather than the beginning of the new section - e.g.

Change
Loop Until theTextLine = "[section 2]"
To
Loop Until theTextLine = "[/section 1]"

 


Lead me not into temptation... I know the short cut, follow me.
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 07 June 2004 at 1:33pm
Sorted out.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set theTextFile = FSO.OpenTextFile("E:\webs\ranbaxyromania.ro\wwwroot\files\tb lViziteDoctori1.txt")

While Not theTextFile.AtEndOfStream
theTextLine=theTextFile.ReadLine
If theTextline = "[section 1]" then
    do
        theTextLine=theTextFile.ReadLine
        ' Only Write it out if it isn't a section line
        If theTextLine<>"[section 2]" Then
            response.Write theTextLine & "<br>"
        End If
    loop Until theTextLine = "[section 2]"
End if

If theTextline = "[section 2]" then
    do
        theTextLine=theTextFile.ReadLine
        ' Only Write it out if it isn't a section line
        If theTextLine<>"[section 3]" Then
            response.write theTextLine & "<br>"
        End IF
    loop Until theTextLine = "[section 3]"
End if

Wend

' Close up to be tidy

theTextFile.Close
Set theTextFile = Nothing

%>

The problem was that, instead of If theTextLine<>"[section 2]", i was putting If theTextLine="[section 2]", which, of course, gave me an error...
Cristian Banu
Soft 4 web
Back to Top
snapey View Drop Down
Newbie
Newbie


Joined: 28 July 2002
Location: United Kingdom
Status: Offline
Points: 33
Post Options Post Options   Thanks (0) Thanks(0)   Quote snapey Quote  Post ReplyReply Direct Link To This Post Posted: 18 June 2004 at 3:45pm

Originally posted by Mart Mart wrote:

Howcome you arn't using XML for this? It will be quite hard to do what you are trying to do and most likely pointless if you could do it with XML

I want to do similar, but using XML. Can anyone point me in the direction of any examples of reading an XML file into an array or database in classic ASP?

 

Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.