Results 1 to 12 of 12

Thread: Trouble With Text Files

  1. #1

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Trouble With Text Files

    Ok i got great help earlier but having a problem o.0

    Private Sub Form_Load()
    Dim sTemp As String
    Dim sTotalString As String
    Shell "C:\File.bat > C:\Irc.txt"
    Open "C:\Irc.txt" For Input As #1
    Do While EOF(1) = False
    Line Input #1, sTemp
    sTotalString = sTotalString & sTemp
    Text1.Text = sTotalString
    Loop
    End Sub


    The First line in the file its opening its blank so i dont think its reading that because of it...The only way i can get output into the textbox is if i click the button twice..
    Last edited by ThaRubby; May 3rd, 2005 at 10:14 PM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Trouble With Text Files

    First, indent your code, and use code tags.

    VB Code:
    1. dim ff as integer
    2.   ff = freefile
    3.   Open "C:\Irc.txt" For Input As #ff
    4.   Do While EOF(1) = False
    5.     Line Input #1, sTemp
    6.     sTotalString = sTotalString & sTemp
    7.   Loop
    8.   Close #1
    9.   text1.text = sTotalString

    You could also read it all at once, with a choice of ways to parse it into lines.
    This also counts the lines!

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim ff As Integer
    5.   Dim strBuff As String
    6.   Dim str() As String
    7.   ff = FreeFile
    8.   Open "C:\Irc.txt"  For Input As #ff
    9.     strBuff = Input(LOF(ff), ff)
    10.   Close #ff
    11.   ' ----------------- two ways to skin a cat --------------
    12.   MsgBox "Lines = " & Len(strBuff) - Len(Replace(strBuff, vbCrLf, "x")) + 1
    13.   ' -------------------------------------------------------
    14.   str() = Split(strBuff, vbCrLf)
    15.   MsgBox "There are " & UBound(str) + 1 & " lines in the file"
    16.  
    17.  
    18. End Sub

  3. #3
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Re: Trouble With Text Files

    Why don't you load the entire file at once?
    VB Code:
    1. Open "C:\Irc.txt" For Input As #1
    2. text1.text = Input(LOF(1), #1)
    3. Close #1

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Trouble With Text Files

    You changed it!
    If you put the code into the form_activate event, it will already be shown when you add the text. I thought it was on a click of a button.

    What does the bat file do? It probably isn't finishing by the time you read irc.txt

  5. #5

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Re: Trouble With Text Files

    microalps, i tried that it didnt work. dglienna yea it is its echoed into the text file just fine but wont display in the text file..

  6. #6
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Trouble With Text Files

    i wrote a whole topic about this in the codebank..

    dim ff as integer
    Open "C:\Irc.txt" For binary As #ff
    text1.text = Input(LOF(ff), #ff)
    Close #ff

  7. #7

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Re: Trouble With Text Files

    Still doesnt work ^.^

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Trouble With Text Files

    It doesn't have time to echo and read at the same time.
    Put the echo into the form load, and the text in a command button.
    That should be enough time. Otherwise you need to wait a few seconds.
    You could also use
    VB Code:
    1. "Start MyBatchFile.bat /wait"

  9. #9
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Re: Trouble With Text Files

    Is the multiline property of text1 set to True? If you don't want it to have any enters then use this code

    VB Code:
    1. Open "C:\Irc.txt" For Input As #1
    2. text1.text = Replace(Input(LOF(1), #1), vbCrLf, "")
    3. Close #1
    This will remove the enters from the input!

  10. #10

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Re: Trouble With Text Files

    Yes it was multiple line.

    Open "C:\Irc.txt" For Input As #1
    text1.text = Replace(Input(LOF(1), #1), vbCrLf, "")
    Close #1


    Worked!

  11. #11
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Re: Trouble With Text Files

    You're welcome. Hope my input didn't confuse you though... Good luck on the rest of your project!

  12. #12
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Trouble With Text Files

    Open "C:\Irc.txt" For Input As #1
    text1.text = Replace(Input(LOF(1), #1), vbCrLf, vbnullstring)
    Close #1

    ^^just optimized it a pinch

    but seriously you should use binary instead

    Open "C:\Irc.txt" For binary As #1
    text1.text = Replace(Input(LOF(1), #1), vbCrLf, vbnullstring)
    Close #1

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