Need help debugging some VB6
So I'm working on a file parser, and I thought I finally had everything ironed our and another wrinkle reared its head. Basically the program takes a single text file with many files inside and separates them all out.
The problem that is giving me issues is when I create a file system object to write the data to file.
The error thrown when I try run the code is:
I have bolded the line in question. This is my first time using file system objects so I had to refer online as how to implement them. I need the output path to change with each new file, so I thought this would work. What am I doing wrong.
And just to put aside any questions, I have checked the value of OutputFileText and as I ran it was "C:\Documents and Settings\ingraal\Desktop\output\Deutsch090627.doc"
The problem that is giving me issues is when I create a file system object to write the data to file.
The error thrown when I try run the code is:
Run-time Error 52
Bad File name or number
I have bolded the line in question. This is my first time using file system objects so I had to refer online as how to implement them. I need the output path to change with each new file, so I thought this would work. What am I doing wrong.
And just to put aside any questions, I have checked the value of OutputFileText and as I ran it was "C:\Documents and Settings\ingraal\Desktop\output\Deutsch090627.doc"
Private Sub Command4_Click()
InputFileText = Text1.Text ' Assign input file
OutputDirText = Text2.Text ' Where the files go
StartPageText = Text3.Text ' What a new confirmation starts with
CoInfoText = Text4.Text ' What the company info starts with
CurrentDate = Format(Now, "yymmdd")
Dim confirmation, company As String ' Current line being read
confirmation = vbNullString ' Set confirmation to be empty
' Create filesystem object and textstream object.
Dim fsys As New FileSystemObject
Dim Output As TextStream
Dim TStream As TextStream
Set TStream = fsys.OpenTextFile(InputFileText, ForReading)
' This is to skip the first few lines of the confirmation. I do this because if the code
' found the deal header right at the beginning it would try to output it with both an empty
' confirmation string and no filename. This is kind of sloppy, but I couldn't think of a
' better solution.
Dim i As Integer
For i = 1 To 5
currentLine = TStream.ReadLine
confirmation = confirmation + currentLine + vbNewLine
Next
Do Until TStream.AtEndOfStream = True ' Start to loop through the file
' psuedo code >> If currentLine contains newpagetext then check dominance & threshold. else output line to current document.
' If dominance & threshhold are true then newdocument. Else, output line to current document.
currentLine = TStream.ReadLine
' We need to handle excessive blank lines as it appears that is too much trouble for them
' to do on the template side of things.. So we will impose a hard limit on the number of
' blank lines allowed before we begin skipping them.
If Len(currentLine) = 0 Then
iBlankLineCounter = iBlankLineCounter + 1
Else
iBlankLineCounter = 0
End If
Dim strmsgbox
' Assign the current working file a name based upon the company it is addressed to.
' The company name is limited to 8 characters in length. Anything after that is truncated.
If InStr(currentLine, CoInfoText) <> 0 Then
company = findCompany(currentLine, CoInfoText)
OutputFileText = OutputDirText & "\" & company & CurrentDate & ".doc"
confirmation = confirmation + currentLine + vbNewLine
' This bit of code is to decide if a new confirmation has begun, or if we should just continue outputting.
ElseIf InStr(currentLine, StartPageText) <> 0 Then
If Dominance(currentLine, StartPageText) And Threshold(currentLine, StartPageText) Then
[B] Set Output = fsys.CreateTextFile(OutputFileText, False) 'Create file to hold current confirmation[/B]
Output.Write (confirmation) 'Dump current confirmation string to file
confirmation = vbNullString 'Clear current confirmation string
confirmation = currentLine + vbNewLine 'Add current line to confirmation string
Output.Close 'Close the object since we are through with it for now. We'll make a new one later.
ElseIf iBlankLineCounter < 3 Then 'To cut down on the number of blank lines. See code above.
confirmation = confirmation + currentLine + vbNewLine 'Add current line to confirmation string
End If
'If neither of the above two, we are going to add on to our current confirmation.
ElseIf iBlankLineCounter < 3 Then
confirmation = confirmation + currentLine + vbNewLine 'Add current line to confirmation string
End If
Loop
'Use this to output parse statistics.
MsgBox "Processing completed" & vbNewLine & "You may exit the program."
End Sub
0
Comments