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.. :no: 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. :notworthy :notworthy
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.
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>
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.