' ****************************************************** ' * ' * Name: tstReadFlatFile.vbs ' * ' * Design Phase: ' * Author: John Miner ' * Date: 06/30/2008 ' * Purpose: A test program to read flat files. ' * ' ****************************************************** ' ' Declare all variables ' Option Explicit ' ' Load the class library ' ExecuteGlobal CreateObject("Scripting.FileSystemObject").OpenTextFile(CurrentPath() & "mod-read-text-file.vbs").ReadAll ' ' Get The Current Program Path ' Function CurrentPath() CurrentPath = Replace(WScript.ScriptFullName, WScript.ScriptName,"") End Function ' ' Unpack the field from the buffer ' Public Function UnpackField(strData, intLength) If len(strData) < intLength Then UnpackField = strData Else UnpackField = Mid(strData, 1, intLength) strData = Mid(strData, intLength+1) End If End Function ' ' Code to test the program ' Public Sub Test() ' The test file name Dim strFile strFile = "c:\vbs-depot\flat\presidents.txt" ' Create the object Dim objTxtFile Set objTxtFile = New clsReadTxtFile ' Open the file objTxtFile.OpenDataFile strFile, ForReading ' Read in the data Dim strLine Dim strField Do ' Read in one line strLine = objTxtFile.PullData strField = "" ' All done If (objTxtFile.EOF) Then Exit Do End If ' Show the data Wscript.Echo UnpackField(strLine, 5) & " - " Wscript.Echo " last name = " & UnpackField(strLine, 15) Wscript.Echo " first name = " & UnpackField(strLine, 15) Wscript.Echo " address 1 = " & UnpackField(strLine, 30) Wscript.Echo " address 2 = " & UnpackField(strLine, 20) Wscript.Echo " city = " & UnpackField(strLine, 20) Wscript.Echo " state = " & UnpackField(strLine, 3) Wscript.Echo " zip = " & UnpackField(strLine, 6) Wscript.Echo " term = " & UnpackField(strLine, 10) Wscript.Echo "" Wscript.Echo "" Loop While (True) ' Close the data file objTxtFile.CloseDataFile End Sub ' Run the test Test