Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Dec 15, 2003

Display a Partial Text File Using FSO

This script reads specific lines of text from any text file and then stores the lines in an array that you can assign to a variable for data display.

<%
Const ForReading = 1

' The following line numbers will be read into the array
Dim myArr(4)
myArr(0)="10"
myArr(1)="12"
myArr(2)="15"
myArr(3)="17"

' Counter used for array increment
i = 0

' Create FSO Object & Set File to Read
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\inetpub\wwwroot\Readme.Txt")

' Open file for reading.
Set objTextFile = objFile.OpenAsTextStream(ForReading)

' Loop Through TEXT File and Get Text to Display
Do While objTextFile.AtEndOfStream <> True
    CurrLine = objTextFile.Line
    If Cstr(CurrLine) = Cstr(myArr(i)) Then
	myArr(i)=UCASE(objTextFile.ReadLine)
        i = i + 1
    Else
        CurrLine = objTextFile.ReadLine
    End If
Loop

' Set variables
Line10 = myArr(0)
Line12 = myArr(1)
Line15 = myArr(2)
Line17 = myArr(3)

' Close & Destroy
objTextFile.Close
Set objFSO = Nothing
Set objFile = Nothing

' Display Data
Response.Write "Line 10 reads: " & Line10
Response.Write "Line 12 reads: " & Line12
Response.Write "Line 15 reads: " & Line15
Response.Write "Line 17 reads: " & Line17
%>
DevX Staff
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date