Results 1 to 6 of 6

Thread: [RESOLVED] Loading a Saved text file and ||

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    12

    Resolved [RESOLVED] Loading a Saved text file and ||

    I'm using the code below to load contents of network.txt in to a text box

    Code:
      sFilename = App.Path & "/config/network.txt"
     If Dir(App.Path & "/config/") <> "" Then
     hFile = FreeFile
       Open sFilename For Input As #hFile
          Text1.Text = Input$(LOF(hFile), hFile)
       Close #hFile
    It does this but add two vertical lines in the text box after it. Any Ideas as this is causing a prob when I then use the contents of network.txt as part of a file path ie

    Code:
     whole_file = GrabFile(Text1.Text & "\trnewsroom\users\users.dat")
    I assume what these vertical lines are doing is causing it to got to c:\tr||\trnewsroom\users\users.dat which is causing it to fail.

    any help would be greatly appreciated.

  2. #2
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: Loading a Saved text file and ||

    I'm curious what the pipes really are for characters
    Can you do this?

    MsgBox asc(right(text1.text,1))

    This will pop up a number between 0 and 255, which one? If it is 13 or 10, you are also taking a carriage return or line feed which might cause the problem. You need to trim this one then, could be done by:

    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 2)

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    12

    Re: Loading a Saved text file and ||

    Its saying 10

  4. #4
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: Loading a Saved text file and ||

    Thats a linefeed (vbLf), you need to remove it then

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    12

    Re: Loading a Saved text file and ||

    Thanks, I found the code below to do that. All works now (prob not the most elegant way of doing it but hey it works).

    Code:
    Dim strV
    
    strV = Text1.Text
    Text2.Text = Replace(strV, Chr(13) & Chr(10), "")
    Text1.Text = Text2.Text

  6. #6
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: [RESOLVED] Loading a Saved text file and ||

    It's cleaner then my solution; just removing the last two chars
    You could replace Chr(13) & Chr(10) by vbCrLf or vbNewLine though, it's shorter and faster.
    See also; http://www.vbforums.com/showthread.php?t=575726

Posting Permissions

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



Click Here to Expand Forum to Full Width