CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: seperate lines

  1. #1
    Join Date
    May 2001
    Posts
    155

    seperate lines

    I have this code in a form:


    private Sub Command1_Click()
    on error resume next
    d.Filter = "TextFiles |*.txt|"
    d.ShowSave
    Open d.filename for Output as #1
    print #1, b.Text
    Close #1
    e.Filter = "TextFiles |*.txt|"
    e.ShowSave
    Open e.filename for Output as #1
    print #1, c.Text
    Close #1
    f.Filter = "Testfile |*.txp|"
    f.ShowSave
    Open f.filename for Output as #1
    print #1, d.filename & Chr(10) & e.filename & Chr(10)
    Close #1

    End Sub

    private Sub Command2_Click()
    on error resume next
    f.Filter = "Text Projects |*.txp|"
    f.ShowOpen
    Open f.filename for input as #1
    Line input #1, txt
    a2.Text = txt
    Line input #2, txt2
    a3.Text = txt2

    b2.LoadFile a2.Text
    c.LoadFile txt
    End Sub



    What it's supposed to do is load 1 file. Seperate the 2 lines from the file into 2 seperate textboxes. Then in the textboxes, it reads the text from the textbox and opens the file from the path in the textbox. THe file is supposed to be opened into another textbox. The second textbox is supposed to do the same thing, except load a different file.

    But when i run it, it only reads 1 line, and only loads 1 file. What am i doing wrong?

    PS The *.txp file looks like this:

    C:\test\000test\a.txt
    C:\test\000test\b.txt

    --Ant
    --------------------------------------------------
    Create rollover effects in no time!, visit:
    http://members.fortunecity.com/ants12/rolloverwiz.html
    Or email me:
    [email protected]

  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: seperate lines

    The Line Input # reads until it encounters a Carriage Return (Chr(13)). Your program which creates the record is using Chr(10) (Line Feed)
    change the statement which reads

    print #1, d.filename & Chr(10) & e.filename & Chr(10)
    ''' to
    print #1, d.filename & Chr(13) & e.filename & Chr(13)

    ' or better yet
    print #1, d.filename & vbCr & e.filename & vbCr




    John G

  3. #3
    Join Date
    May 2001
    Posts
    155

    Re: seperate lines

    Ok, i've changed that, but it still loads only 1 file. Try testing out the code, the maybe you can tell me how to fix it

    Thanks!

    --Ant
    --------------------------------------------------
    Create rollover effects in no time!, visit:
    http://members.fortunecity.com/ants12/rolloverwiz.html
    Or email me:
    [email protected]

  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: seperate lines

    Testing your program. Command1 problem. Using vbCr instead of chr(10) I mentioned in earlier post solved problem of only reading one line

    '
    Command2 has two problems
    Line Input #2,txt2
    ' Should read
    Line Input #1, txt2
    c.Loadfile txt
    ' should read
    c.loadfile a3.txt
    '
    Here is the corrected copy

    private Sub Command1_Click()
    'on error resume next
    d.Filter = "TextFiles |*.txt|"
    d.ShowSave
    Open d.FileName for Output as #1
    print #1, b.Text
    Close #1
    e.Filter = "TextFiles |*.txt|"
    e.ShowSave
    Open e.FileName for Output as #1
    print #1, c.Text
    Close #1
    f.Filter = "Testfile |*.txp|"
    f.ShowSave
    Open f.FileName for Output as #1
    print #1, d.FileName & vbCr & e.FileName & vbCr
    Close #1

    End Sub

    private Sub Command2_Click()
    'on error resume next
    f.Filter = "Text Projects |*.txp|"
    f.ShowOpen
    Open f.FileName for input as #1
    Line input #1, txt
    a2.Text = txt
    Line input #1, txt2
    a3.Text = txt2

    b2.LoadFile a2.Text
    c.LoadFile a3.Text
    End Sub





    NOTE: To find the errors, I commented the ON ERROR RESUME NEXT statements. They tend to mask a lot of problems.


    John G

  5. #5
    Join Date
    May 2001
    Posts
    155

    Re: seperate lines

    Thanks alot! It works perfectly now.

    --Ant
    --------------------------------------------------
    Create rollover effects in no time!, visit:
    http://members.fortunecity.com/ants12/rolloverwiz.html
    Or email me:
    [email protected]

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

Featured