Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Active Server Pages (ASP)
Expertise: Beginner
Oct 5, 2000



Application Security Testing: An Integral Part of DevOps

Displaying Quotations from Text Files

How do I return only the first four lines (a quotation) of a txt-file to my asp-file?

Use the FileSystem Object to open the text file and then read the first four lines into a string variable. Then write the string variable out on to your Web site.

First, create a FileSystemObject object.

Dim fs, f, strOneLine, i
   Dim strResult
   Set fs = CreateObject("Scripting.FileSystemObject")
Next, create a TextStream Object out of the FileSysemObject.
 Set f = fs.OpenTextFile("c:\testfile.txt", 1,0)
   ' -- in above code,
   ' -- 1 = for reading
   ' -- 0 = TriStateFalse
Read the first four lines from the TextStream Object. Use the AtEndOfStream property to make sure you are not at end of file.
 i = 0
   strResult = ""
   Do While f.AtEndOfStream <> True    
      i = i+1
      if i > 4 then
        ' -- we have read the first four lines
        ' -- get out
        Exit Do
      End if
      strOneLine = F.ReadLine    
      ' -- do something with your line
      strResult = strResult & vbCrlf & strOneLine
Finally, close all your objects.
   Set f = Nothing
   Set fs = Nothing

Output your text
   Response.write strResult
DevX Pro
Comment and Contribute






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



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date