SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    reading array elements from a txt file

    hello,

    i am able to read from a txt file and this is the code:



    Code:
    Const fsoForReading = 1
    	 
    	 Dim objFSO
    	 Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    	 
    	 'Open the text file
    	 
    	 Dim objTextStream,i
    	 Set objTextStream = objFSO.OpenTextFile("C:\test\testingArrayElements.txt", fsoForReading)
       'Display the contents of the text file
       Response.Write objTextStream.ReadAll
    objTextStream.Close
     Set objTextStream = Nothing
     Set objFSO = Nothing
    how can i loop the content of this txt file like an array?
    my normal code which has an array and a for loop looks like this:


    Code:
    Dim extracturlArr(4),i
    	 
    	 extracturlArr(1) ="http://pww.xray.ms.philips.com/cmt_..._682/2_682.html"
    	 extracturlArr(2)= "http://pww.xray.ms.philips.com/cmt_..._735/2_735.html"
    	 extracturlArr(3)= "http://pww.xray.ms.philips.com/cmt_..._640/2_640.html"
    	 extracturlArr(4)= "http://pww.xray.ms.philips.com/cmt_..._680/2_680.html"
    For i = 1 to 4
    	strRetVal = strRetVal+xObj.Retrieve(extracturlArr(i),Request_G  ET,"","","")
    	 next
    i have now the array elements in my txt file and i want to do the same thing as above but now i want to read and loop them from a txt file. can anybody direct me how can i customize these two pieces of code????

  2. #2
    SitePoint Addict danfran's Avatar
    Join Date
    Jan 2005
    Location
    New York City
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how can i loop the content of this txt file like an array?
    Use the ReadLine() method and the AtEndOfStream property.. Always refer to the MSDN library when trying to work with native Microsoft components!

    A snippet from http://msdn.microsoft.com/library/de...threadline.asp
    Code:
    Function ReadEntireFile(filespec)
       Const ForReading = 1
       Dim fso, theFile, retstring
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set theFile = fso.OpenTextFile(filespec, ForReading, False)
       Do While theFile.AtEndOfStream <> True
          retstring = theFile.ReadLine
       Loop
       theFile.Close
       ReadEntireFile = retstring
    End Function
    -Dan


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •