kingesk
09-07-2000, 04:13 PM
'This program should GET a text file, then output only
'the records I want with different field lengths.
'It worked with only 1 record but when I used a file
'with many records only the 1st record was formatted
'and the rest were output but not in the correct format.
'Any sugestions would be appreciated.
'module level variables
'file name strings
Dim mstrInputFileName As String
Dim mstrOutputFileName As String
'define the input record format
Private Type InputRecord
strType As String * 1
strID As String * 4
strBenefit As String * 4
strApp As String * 3
strLocation As String * 4
strSchedule As String * 2
strDate As String * 8
strSSN As String * 9
strFirst As String * 20
strLast As String * 20
strStreet1 As String * 30
strStreet2 As String * 30
strCity As String * 32
strState As String * 2
strZip As String * 9
strBirthDate As String * 8
strEmpDate As String * 8
strTermDate As String * 8
strRehireDate As String * 8
strSex As String * 1
strKey As String * 1
strStatus As String * 1
strEffDate As String * 8
strSalary As String * 11
strDedCode1 As String * 3
strAmount1 As String * 6
strDedCode2 As String * 3
strAmount2 As String * 6
strDedCode3 As String * 3
strAmount3 As String * 6
strDedCode4 As String * 3
strAmount4 As String * 6
strDedCode5 As String * 3
strAmount5 As String * 6
strDedCode6 As String * 3
strAmount6 As String * 6
strTotalAmount As String * 8
End Type
'define the output record format
Private Type OutputRecord
strFirst As String * 10
strLast As String * 10
strSex As String * 1
strKey As String * 1
strStatus As String * 2
strSSN As String * 9
strBirthDate As String * 8
strEmpDate As String * 8
strSalary As String * 8
strStreet1 As String * 25
strStreet2 As String * 25
strCity As String * 15
strState As String * 2
strZip As String * 9
strDedCode1 As String * 3
strAmount1 As String * 6
strDedCode2 As String * 3
strAmount2 As String * 6
strDedCode3 As String * 3
strAmount3 As String * 6
strDedCode4 As String * 3
strAmount4 As String * 6
strDedCode5 As String * 3
strAmount5 As String * 6
strDedCode6 As String * 3
strAmount6 As String * 6
strDedCode7 As String * 3
strAmount7 As String * 6
strDedCode8 As String * 3
strAmount8 As String * 6
strDedCode9 As String * 3
strAmount9 As String * 6
strTotalAmount As String * 8
strTermDate As String * 8
End Type
Option Explicit
Private Sub cmdExit_Click()
'Exit the application
End
End Sub
Private Sub cmdFormat_Click()
'This method will perform the reformatting of the input file
'and generate an output file of the selected name and path
'define our buffers
Dim udtInputRecord As InputRecord
Dim udtOutputRecord As OutputRecord
'local variables
Dim intNumRecords As Integer
Dim intIndex As Integer
'get the input file name
dlgCommon.DialogTitle = "Select Input File"
dlgCommon.InitDir = "a:""
dlgCommon.FileName = vbNullString
dlgCommon.Filter = "*.txt"
dlgCommon.ShowOpen
mstrInputFileName = dlgCommon.FileName
'get output file name
dlgCommon.DialogTitle = "Select Output File"
dlgCommon.InitDir = "a:""
dlgCommon.FileName = vbNullString
dlgCommon.Filter = "*.txt"
dlgCommon.ShowOpen
mstrOutputFileName = dlgCommon.FileName
'clear out the output file
Open mstrOutputFileName For Output As #2
Close #2
'open the input and output files
Open mstrInputFileName For Random As #1 Len = Len(udtInputRecord)
Open mstrOutputFileName For Random As #2 Len = Len(udtOutputRecord)
'perform reformatting function
intNumRecords = LOF(1) / Len(udtInputRecord)
For intIndex = 1 To intNumRecords
Get #1, intIndex, udtInputRecord
udtOutputRecord.strFirst = udtInputRecord.strFirst
udtOutputRecord.strLast = udtInputRecord.strLast
udtOutputRecord.strSex = udtInputRecord.strSex
udtOutputRecord.strKey = udtInputRecord.strKey
udtOutputRecord.strStatus = udtInputRecord.strStatus
udtOutputRecord.strSSN = udtInputRecord.strSSN
udtOutputRecord.strBirthDate = udtInputRecord.strBirthDate
udtOutputRecord.strEmpDate = udtInputRecord.strEmpDate
udtOutputRecord.strSalary = udtInputRecord.strSalary
udtOutputRecord.strStreet1 = udtInputRecord.strStreet1
udtOutputRecord.strStreet2 = udtInputRecord.strStreet2
udtOutputRecord.strCity = udtInputRecord.strCity
udtOutputRecord.strState = udtInputRecord.strState
udtOutputRecord.strZip = udtInputRecord.strZip
udtOutputRecord.strDedCode1 = udtInputRecord.strDedCode1
udtOutputRecord.strAmount1 = udtInputRecord.strAmount1
udtOutputRecord.strDedCode2 = udtInputRecord.strDedCode2
udtOutputRecord.strAmount2 = udtInputRecord.strAmount2
udtOutputRecord.strDedCode3 = udtInputRecord.strDedCode3
udtOutputRecord.strAmount3 = udtInputRecord.strAmount3
udtOutputRecord.strDedCode4 = udtInputRecord.strDedCode4
udtOutputRecord.strAmount4 = udtInputRecord.strAmount4
udtOutputRecord.strDedCode5 = udtInputRecord.strDedCode5
udtOutputRecord.strAmount5 = udtInputRecord.strAmount5
udtOutputRecord.strDedCode6 = udtInputRecord.strDedCode6
udtOutputRecord.strAmount6 = udtInputRecord.strAmount6
udtOutputRecord.strDedCode7 = " "
udtOutputRecord.strAmount7 = " "
udtOutputRecord.strDedCode8 = " "
udtOutputRecord.strAmount8 = " "
udtOutputRecord.strDedCode9 = " "
udtOutputRecord.strAmount9 = " "
udtOutputRecord.strTotalAmount = udtInputRecord.strTotalAmount
udtOutputRecord.strTermDate = udtInputRecord.strTermDate
'write output record to file
Put #2, intIndex, udtOutputRecord
Next
'close the files
Close #1
Close #2
End Sub
'the records I want with different field lengths.
'It worked with only 1 record but when I used a file
'with many records only the 1st record was formatted
'and the rest were output but not in the correct format.
'Any sugestions would be appreciated.
'module level variables
'file name strings
Dim mstrInputFileName As String
Dim mstrOutputFileName As String
'define the input record format
Private Type InputRecord
strType As String * 1
strID As String * 4
strBenefit As String * 4
strApp As String * 3
strLocation As String * 4
strSchedule As String * 2
strDate As String * 8
strSSN As String * 9
strFirst As String * 20
strLast As String * 20
strStreet1 As String * 30
strStreet2 As String * 30
strCity As String * 32
strState As String * 2
strZip As String * 9
strBirthDate As String * 8
strEmpDate As String * 8
strTermDate As String * 8
strRehireDate As String * 8
strSex As String * 1
strKey As String * 1
strStatus As String * 1
strEffDate As String * 8
strSalary As String * 11
strDedCode1 As String * 3
strAmount1 As String * 6
strDedCode2 As String * 3
strAmount2 As String * 6
strDedCode3 As String * 3
strAmount3 As String * 6
strDedCode4 As String * 3
strAmount4 As String * 6
strDedCode5 As String * 3
strAmount5 As String * 6
strDedCode6 As String * 3
strAmount6 As String * 6
strTotalAmount As String * 8
End Type
'define the output record format
Private Type OutputRecord
strFirst As String * 10
strLast As String * 10
strSex As String * 1
strKey As String * 1
strStatus As String * 2
strSSN As String * 9
strBirthDate As String * 8
strEmpDate As String * 8
strSalary As String * 8
strStreet1 As String * 25
strStreet2 As String * 25
strCity As String * 15
strState As String * 2
strZip As String * 9
strDedCode1 As String * 3
strAmount1 As String * 6
strDedCode2 As String * 3
strAmount2 As String * 6
strDedCode3 As String * 3
strAmount3 As String * 6
strDedCode4 As String * 3
strAmount4 As String * 6
strDedCode5 As String * 3
strAmount5 As String * 6
strDedCode6 As String * 3
strAmount6 As String * 6
strDedCode7 As String * 3
strAmount7 As String * 6
strDedCode8 As String * 3
strAmount8 As String * 6
strDedCode9 As String * 3
strAmount9 As String * 6
strTotalAmount As String * 8
strTermDate As String * 8
End Type
Option Explicit
Private Sub cmdExit_Click()
'Exit the application
End
End Sub
Private Sub cmdFormat_Click()
'This method will perform the reformatting of the input file
'and generate an output file of the selected name and path
'define our buffers
Dim udtInputRecord As InputRecord
Dim udtOutputRecord As OutputRecord
'local variables
Dim intNumRecords As Integer
Dim intIndex As Integer
'get the input file name
dlgCommon.DialogTitle = "Select Input File"
dlgCommon.InitDir = "a:""
dlgCommon.FileName = vbNullString
dlgCommon.Filter = "*.txt"
dlgCommon.ShowOpen
mstrInputFileName = dlgCommon.FileName
'get output file name
dlgCommon.DialogTitle = "Select Output File"
dlgCommon.InitDir = "a:""
dlgCommon.FileName = vbNullString
dlgCommon.Filter = "*.txt"
dlgCommon.ShowOpen
mstrOutputFileName = dlgCommon.FileName
'clear out the output file
Open mstrOutputFileName For Output As #2
Close #2
'open the input and output files
Open mstrInputFileName For Random As #1 Len = Len(udtInputRecord)
Open mstrOutputFileName For Random As #2 Len = Len(udtOutputRecord)
'perform reformatting function
intNumRecords = LOF(1) / Len(udtInputRecord)
For intIndex = 1 To intNumRecords
Get #1, intIndex, udtInputRecord
udtOutputRecord.strFirst = udtInputRecord.strFirst
udtOutputRecord.strLast = udtInputRecord.strLast
udtOutputRecord.strSex = udtInputRecord.strSex
udtOutputRecord.strKey = udtInputRecord.strKey
udtOutputRecord.strStatus = udtInputRecord.strStatus
udtOutputRecord.strSSN = udtInputRecord.strSSN
udtOutputRecord.strBirthDate = udtInputRecord.strBirthDate
udtOutputRecord.strEmpDate = udtInputRecord.strEmpDate
udtOutputRecord.strSalary = udtInputRecord.strSalary
udtOutputRecord.strStreet1 = udtInputRecord.strStreet1
udtOutputRecord.strStreet2 = udtInputRecord.strStreet2
udtOutputRecord.strCity = udtInputRecord.strCity
udtOutputRecord.strState = udtInputRecord.strState
udtOutputRecord.strZip = udtInputRecord.strZip
udtOutputRecord.strDedCode1 = udtInputRecord.strDedCode1
udtOutputRecord.strAmount1 = udtInputRecord.strAmount1
udtOutputRecord.strDedCode2 = udtInputRecord.strDedCode2
udtOutputRecord.strAmount2 = udtInputRecord.strAmount2
udtOutputRecord.strDedCode3 = udtInputRecord.strDedCode3
udtOutputRecord.strAmount3 = udtInputRecord.strAmount3
udtOutputRecord.strDedCode4 = udtInputRecord.strDedCode4
udtOutputRecord.strAmount4 = udtInputRecord.strAmount4
udtOutputRecord.strDedCode5 = udtInputRecord.strDedCode5
udtOutputRecord.strAmount5 = udtInputRecord.strAmount5
udtOutputRecord.strDedCode6 = udtInputRecord.strDedCode6
udtOutputRecord.strAmount6 = udtInputRecord.strAmount6
udtOutputRecord.strDedCode7 = " "
udtOutputRecord.strAmount7 = " "
udtOutputRecord.strDedCode8 = " "
udtOutputRecord.strAmount8 = " "
udtOutputRecord.strDedCode9 = " "
udtOutputRecord.strAmount9 = " "
udtOutputRecord.strTotalAmount = udtInputRecord.strTotalAmount
udtOutputRecord.strTermDate = udtInputRecord.strTermDate
'write output record to file
Put #2, intIndex, udtOutputRecord
Next
'close the files
Close #1
Close #2
End Sub