vbScript Example: Write to text file, read first 7 characters in file and display result

This method reads the number of characters you specify from a Textstream file and returns them as a string. If you specify more characters than actual exist in the file, then Read only returns the actual number of characters that are in the file. The results are stored in the [result] neobook variable.

:Code

dim filesys, text, readfile, contents
set filesys = CreateObject("Scripting.FileSystemObject")
Set text = filesys.CreateTextFile("c:\somefile2.txt")
text.Write "A quick example of the Read method"
text.close
set readfile = filesys.OpenTextFile("c:\somefile2.txt", 1, false)
contents = readfile.Read(7)
readfile.close

publication.nbSetVar "[result]", "The first seven characters in the text file are '" & contents & "'."

:End Code

You can use vbscript in NeoBook RAD5. Click here.