Displaying Quotations from Text Files

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:	estfile.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   Loop

Finally, close all your objects.

 F.Close   Set f = Nothing   Set fs = NothingOutput your text   Response.write strResult

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved