Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Converting Unix files to DOS files for import.

Status
Not open for further replies.

GComyn

Programmer
Jul 24, 2001
177
US
Greetings...

I found the following code somewhere on the net, I forget where, that will convert a text file from Unix format to DOS format. However, if the file is too big, you get an overflow error when you pass the string to the function.

Here is the code for Lf2Crlf:

Code:
Public Function Lf2Crlf(InputString As String, StringLength As Integer) As String
    'InputString is the string to convert
    'StringLength is the length of the string
    
    Dim InstrPos As Long
    Dim StartPos As Integer
    StartPos = 1
    InstrPos = InStr(StartPos, InputString, vbLf)
    
    Do Until InstrPos = 0
        'insert the CRLF
        InputString = Left(InputString, InstrPos - 1) & vbCrLf & Right(InputString, Len(InputString) - InstrPos)
        StartPos = InstrPos + 2
        InstrPos = InStr(StartPos, InputString, vbLf)
    Loop
    Lf2Crlf = InputString
End Function

here is the section of the code I'm using to call the above function:

Code:
...
    intInputFileNumber = FreeFile
    intOutputFileNumber = FreeFile + 1
    Open strSourceFile For Input As #intInputFileNumber
    Open strPathName & strNewFileName For Output As #intOutputFileNumber
    Do While Not EOF(intInputFileNumber)
        Line Input #intInputFileNumber, strLine
        If Len(strLine) = 0 Then strLine = " "
        strLine = Lf2Crlf(strLine, Len(strLine))  '** This is where the error occurs
        Print #intOutputFileNumber, strLine
    Loop
    Close
...


This works great in nearly every instance, but if the file being passed to it is too large, then it doesn't run.

Since Access reads the entire Unix formatted file in as a line, it tries to pass the entire file to the above function as a line.... and that give an Overflow error.

I could just take the pertanent portions from this function and put them into every function that I call it from... but that would not be modular. If it comes to it, I will...


Any help would be appreciated

GComyn
 
GComyn,

I don't have an example off-hand, but you could open
the original file for binary input, read it byte-by-byte,

If vbLF Then
print #2
Else
print #2, inchar;
End If

hth,
Wayne
 
Ok... I guess I'll have to change the function.... so that it read the file in itself...

Right now, it doesn't do the reading of the file. The calling function reads the file, then passes the line to it.

Actually... that would probably tbe the best way to go about it.

Thanks... any other suggestions would be heeded.

GComyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top