Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Read Multiple Lines From A Text File
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Read Multiple Lines From A Text File

 Post Reply Post Reply
Author
neotrix View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 09 November 2003
Location: Pakistan
Status: Offline
Points: 433
Post Options Post Options   Thanks (0) Thanks(0)   Quote neotrix Quote  Post ReplyReply Direct Link To This Post Topic: Read Multiple Lines From A Text File
    Posted: 10 June 2004 at 11:05pm
Originally posted by dpyers dpyers wrote:

You never go to the next line... Move

theTextLine=theTextFile.ReadLine
theFields=Split(theTextLine, VBTab)

After

While Not theTextFile.AtEndOfStream

Hello, well can anyone please explain this a little further, like how to read multiple lines from a text file, i really dont understand anything from the code and i need it very badly...

what i want to do is my text file'z contents will be

Originally posted by MyTextFile.txt MyTextFile.txt wrote:

MovieTitle
SongName1
SongName2
SongName3

i basically want to read 22 lines from a text file, (It is known, and the format of the text file is fixed) i want to store each line in different variables like strVariable1 strVariable2 strVariable3 etc etc... dont know if i can explain my self or not.. but what shud i do ?? I dont think it will be difficult ?

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: 11 June 2004 at 12:56am

Not Tested

<%
'Create your own instance of a File System Object
Set myFSO = Server.CreateObject("Scripting.FileSystemObject")

'Use your FSO to "read" the entire file into a work area
Set strEntireTextFile = myFSO.OpenTextFile("C:\mydirectory\myfile.txt")

'Initialize a line counter
strLineCount = 0

'Do the following loop until the end of data
While Not strEntireTextFile.AtEndOfStream

'Read one line and increment the count of lines read
strSingleTextLine=theTextFile.ReadLine
strLineCount = strLineCount + 1

If strLineCount < 23 then

 'Do stuff depending upon which line you're on
 Select Case strLineCount
  Case 1
   strline1 = strSingleTextLine
  Case 2
   strline2 = strSingleTextLine
  Case 3
   strline3 = strSingleTextLine
   .
   .
   .
  Case 22
   strline22 = strSingleTextLine
 End Select

End If

' Go bact to the beginning of the loop
Wend

'Free the resources used
strEntireTextFile.Close
Set strEntireTextFile = Nothing
%>



Edited by dpyers

Lead me not into temptation... I know the short cut, follow me.
Back to Top
neotrix View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 09 November 2003
Location: Pakistan
Status: Offline
Points: 433
Post Options Post Options   Thanks (0) Thanks(0)   Quote neotrix Quote  Post ReplyReply Direct Link To This Post Posted: 11 June 2004 at 1:24am

Thankyou so very very Much... Xactly What i Needed

Another small Question......

Can u tell me how can i store the names of files found a perticular folder inside an array ?

Thanks

Back to Top
neotrix View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 09 November 2003
Location: Pakistan
Status: Offline
Points: 433
Post Options Post Options   Thanks (0) Thanks(0)   Quote neotrix Quote  Post ReplyReply Direct Link To This Post Posted: 11 June 2004 at 1:43am

You Posted This Code Somewhere... (i've modified it a liiiiiiiiiiiitttle bit)

Originally posted by dpyers dpyers wrote:


Set oFSO = CreateObject("Scripting.FileSystemObject")

CurrentPath = Server.MapPath("data")
Set oFolder = oFSO.GetFolder(CurrentPath)
Set oFolderContents = oFolder.Files

dim i
i = 0
For Each File in oFolder.Files
     Response.Write file.Name  & "<br />"
next

Set oFolder = Nothing
Set oFolderContents = Nothing
Set oFSO = Nothing

It dose work very well.. but the problem i see in this, is that it also writes the file extension (.txt) i want it to write the file name.. and skip the extension, is it possible



Edited by neotrix
Back to Top
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: 11 June 2004 at 2:57am
Left(File.Name, InStrRev(File.Name, ".") - 1) Should work
Back to Top
 Post Reply Post Reply

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.