Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    May 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reading a text file to a variable (VB6)

    I'm using the below code to load a text file (html) to a variable.....but i only get the last 70-80 lines or so for some reason? HELP!!

    Public Function LoadFile(FilePath As _
    String, Optional Append As Boolean = False) As Boolean

    Dim iFile As Integer

    If Dir(FilePath) = "" Then Exit Function

    On Error GoTo ErrorHandler:

    iFile = FreeFile
    Open FilePath For Input As #iFile
    sHTML = Input(LOF(iFile), #iFile)

    LoadFileToTB = True

    Debug.Print sHTML

    ErrorHandler:
    If iFile > 0 Then Close #iFile

    End Function

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Reading a text file to a variable (VB6)

    What is sHTML defined as? Is it a limitation of that definition?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Reading a text file to a variable (VB6)

    Do not judge the size of a variable by the Debug window; it probably can't hold the whole string. Instead, try:

    Debug.Print Len(sHTML)

    to gauge whether it is holding all the text.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Reading a text file to a variable (VB6)

    Also, you might want to take advantage of some of the methods of the FileSystemObject, which is part of the Scripting library. In particular, take a look at the Read and ReadAll methods of the TextStream Object. If your file is large, see the article Efficiently Reading Large Text Files on the 4GuysFromRolla ASP site for advice on these methods.

  5. #5
    New Lounger
    Join Date
    May 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reading a text file to a variable (VB6)

    actually, it was simply becuase the Debug screen could not contain all the text. thx anyways

  6. #6
    New Lounger
    Join Date
    May 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reading a text file to a variable (VB6)

    that's what the problem was, thx.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •