tailieunhanh - Microsoft WSH and VBScript Programming for the Absolute Beginner Part 27

Microsoft WSH and VBScript Programming for the Absolute Beginner by Jerry Lee Ford Part 27. If you are new to programming with Microsoft WSH and VBScript and are looking for a solid introduction, this is the book for you. Developed by computer science professors, books in the for the absolute beginner series teach the principles of programming through simple game creation. You will acquire the skills that you need for more practical WSH and VBScript programming applications and will learn how these skills can be put to use in real-world scenarios. Best of all, by the time you finish this book,. | Microsoft WSH and VBScript Programming for the Absolute Beginner Second Edition Description This script demonstrates how to create open and write a line of text to a text file. Initialization Section Option Explicit Dim objFso objFileHandle strFileName Set objFso strFileName C Temp Main Processing Section OpenTextFile WriteTextOutput CloseTextFile TerminateScript Procedure Section Function OpenTextFile If exists open it in append mode otherwise create and open a new file If strFileName Then Set objFileHandle strFileName 8 Else Set objFileHandle strFileName 2 True End If Chapter 8 Storing and Retrieving Data End Function Function WriteTextOutput Write 3 lines of text to the text file Once upon a time there was a little boy who lived in a shoe. Unfortunately it was two sizes too small End Function Function CloseTextFile Close the file when done working with it End Function Function TerminateScript Stop the execution of this script End Function It is very important that you always remember to close any open files before allowing your scripts to end. You do this by using the FileSystemObject object s Close method as shown here If you forget to close a file after working with it the file might become corrupted because the end-of-file marker has not been created for it. You can only open a file using one mode at a time. In other words if you open a KpV file in ForReading mode your script cannot write new text to the file unless you first close the file and then open it again in ForWriting mode. Microsoft WSH and VBScript Programming for the Absolute Beginner Second Edition If you save and run this script and then open the file using Windows Notepad you ll see the output shown in Figure . Figure Writing to a new or .