Results 1 to 4 of 4

Thread: How to use TextStream in VBScript?

  1. #1
    Join Date
    Jul 2010
    Posts
    38

    How to use TextStream in VBScript?

    I have recently started using the VBScript, and I am not having much idea about using TextStream. I just know that VBScript provides us with the TextStream, through which you can create, read and write to a text file. Applications related to this subject are numerous, for example, you can make a counter. That's it. I am not knowing anything more about the TextStream.. So thought that you members will provide some help. It would be helpful for me, if you members provide some coding due to which I can understand it soon.

  2. #2
    Join Date
    Dec 2008
    Posts
    183

    Re: How to use TextStream in VBScript?

    Applications related to this subject are numerous, for example, you can make a counter: it each time the page is read the value in the text file, and rewrites it increased by one. Or you can create a file for the statistics, in which to store the date and time you access a page. We start with make a counter:
    Code:
    <SCRIPT Language=vbscript> 
    <! - 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    counter = "c: counter.txt" 
    if not fso.FileExists (counter) then 
    fso.CreateTextFile (counter) 
    December OggFile fso.GetFile = (counter) 
    December OggTextStream OggFile.OpenAsTextStream = (2) 
    OggTextStream.WriteLine "0" 
    OggTextStream.Close 
    end if 
    December OggFile fso.GetFile = (counter) 
    
    December OggTextStream1 OggFile.OpenAsTextStream = (1) 
    value = OggTextStream1.ReadLine 
    OggTextStream1.Close 
    
    December OggTextStream OggFile.OpenAsTextStream = (2) 
    OggTextStream.WriteLine cstr (cint (value) +1) 
    OggTextStream.Close 
    //--> 
    </ SCRIPT>
    The script is composed of a first part which deals with whether there is a text file, if does not exist, create it and insert into a value of 0.

  3. #3
    Join Date
    Dec 2008
    Posts
    202

    Re: How to use TextStream in VBScript?

    The next step is to read the value contained in the text file, which is then incremented and written in a text file. Note the difference between access to the file for writing and reading in reading has OpenAsTextStream (1), while in writing OpenAsTextStream (2). The other way to open the text file is in queue, using OpenAsTextStream (8). The write queue is precisely what we need to create a log file.
    Code:
    <SCRIPT Language=vbscript> 
    <! - 
    Set fso = CreateObject ("Scripting.FileSystemObject") 
    logfile = "c: logfile.txt" 
    if not fso.FileExists (logfile) then 
    fso.CreateTextFile (logfile) 
    end if 
    December OggFile fso.GetFile = (log file) 
    
    December OggTextStream OggFile.OpenAsTextStream = (8) 
    OggTextStream.WriteLine now () 
    OggTextStream.Close 
    
    December OggTextStream1 OggFile.OpenAsTextStream = (1) 
    Do While Not OggTextStream1.AtEndOfStream 
    string = OggTextStream1.ReadLine 
    document.write string & "<br> 
    loop 
    OggTextStream1.Close 
    //--> 
    </ SCRIPT>

  4. #4
    Join Date
    Apr 2008
    Posts
    193

    Re: How to use TextStream in VBScript?

    Even in this application is checked for the existence of log files and, if necessary, is created. The file is then opened and the queue is written the date and time of access. To demonstrate the operation, the file is then opened and a Do-While Loop displays all access. As the object file system, also TextStream is used mostly server side. In the two years just proposed, we have indeed created a counter to access such as one sees in many websites, and a statistics file. Not only text files can be used as a configuration file, or if you are able, can be used as a database for small applications. Some boards will take advantage of two text files to work, one for users and one for messages. Would be a good exercise to test the knowledge of VBScript learned so far.

Similar Threads

  1. How to run a .bat file with VBScript ?
    By troy in forum Software Development
    Replies: 8
    Last Post: 29-06-2012, 10:55 AM
  2. What are the TextStream Object in ASP?
    By Silent~Kid in forum Software Development
    Replies: 4
    Last Post: 30-01-2010, 07:07 PM
  3. VBScript for .NET
    By Bharat89 in forum Software Development
    Replies: 3
    Last Post: 03-12-2009, 04:50 PM
  4. help with vbscript
    By andrakis2 in forum Networking & Security
    Replies: 3
    Last Post: 24-08-2009, 06:13 AM
  5. How can I add a new line to vbscript?
    By Baani in forum Software Development
    Replies: 2
    Last Post: 29-05-2009, 04:54 PM

Tags for this Thread

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
  •  
Page generated in 1,713,956,877.07749 seconds with 17 queries