We help IT Professionals succeed at work.
Get Started

Using VB, a text line read in is not yielding correct record length ... any ideas for this newbie?

bhindbjorgen asked
Last Modified: 2013-12-26
I am reading in a file containing records of variable length ... some of which are quite long (over 4096 characters).  For these records, I am wishing to handle differently than those that are less than 4096 characters in length.  The problem is with the Len().  It is not yielding the correct length for me on these long records.  I am attaching code and input file.  
Thanks in advance.  Brad.
FileToDelete = ("WCR-PreSort.txt")
    If objFSO.FileExists(FileFolder & FileToDelete) = True Then
        Dim objOutputFile
        Set objOutputFile = objFSO.CreateTextFile(FileFolder & FileToDelete, True)
        objFSO.DeleteFile (FileFolder & FileToDelete)
        ' MsgBox "Msg from Form's VB Code ... File(s) do not exist."
    End If
    Dim SourceNum, DestNum, RecLength As Integer
    Dim ReadLine, strText As String
    SourceNum = FreeFile()
    Open "C:\Case Reports\Access Data\WCR-Merged2.txt" For Input As SourceNum
    DestNum = FreeFile()
    Open "C:\Case Reports\Access Data\WCR-PreSort.txt" For Append As DestNum
    Do While Not EOF(SourceNum)
    Input #SourceNum, ReadLine
    RecLength = Len(ReadLine)
    If RecLength > 4095 Then
        strText = "Due to content length, this text cannot be viewed here."
        strText = ReadLine
    End If
    Print #DestNum, strText
    Close #DestNum
    Close #SourceNum
    Exit Sub

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE