' ****************************************************** ' * ' * Name: modWriteTextFile.vbs ' * ' * Design Phase: ' * Author: John Miner ' * Date: 06/30/2008 ' * Purpose: A module to write text files. ' * ' ****************************************************** ' ' 1 - Define a module to write a text file ' ' Declare all variables Option Explicit ' Define constants Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 ' ' Define the class ' Class clsWriteTxtFile ' File system object Dim objFso ' A file object Dim objFile ' ' A - Define open method ' Public Sub OpenDataFile(strOpenFile, intMode) ' Remove existing file If (intMode = ForWriting) Then RemoveFile strOpenFile, True End If ' Create the object Set objFso = CreateObject("Scripting.FileSystemObject") ' Open the file Set objFile = objFso.OpenTextFile(strOpenFile, intMode, True) End Sub ' ' B - Define push method ' Public Sub PushData(strData) ' Write out the data objFile.WriteLine strData End Sub ' ' C - Define close method ' Public Sub CloseDataFile() ' Close the file objFile.Close ' Release the file object Set objFile = Nothing ' Release the file system object Set objFso = Nothing End Sub ' ' D - Define remove the file method ' Private Sub RemoveFile(strFile, intYes) ' Nothing to do If Not intYes Then Exit Sub End if ' Declare file variables Dim objFSO Dim objFile ' Get the file system object Set objFSO = CreateObject("Scripting.FileSystemObject") ' Remove old file if it exists! If objFSO.FileExists(strFile) Then Set objFile = objFSO.GetFile(strFile) objFile.Delete End If ' Clean up objects Set objFile = Nothing Set objFSO = Nothing End Sub End Class