• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Simple code to display a poem from file

I am using VB2 to learn the basics of VB.  I used a VB2 text as a reference to answer the task at hand.  This should be very easy but the code from the book did not work.
The question is to create a programme that  will
a) Allow the user to enter a poem into a text box
b) Allow the user to save to file
c) On form load, Load the poem from the file into the text box.

It is C that I have trouble with.  I manage to load the entire poem into a single string variable no problems.  According to my book, using a variable (NL) holding these values "chr$(13) & chr$(10)" would force a new line so that the poem is not one long line.

This didn't work.

Here is the code I used:

Sub Form_Load ()
  Dim Poem As String
  Dim PoemLine As String
  Dim count As Integer
  Dim NL As String
  NL = Chr$(13) & Chr$(10)
    Open "a:\Poem.txt" For Input As #1
    count = 1
    Do Until (EOF(1) = True)
        Input #1, PoemLine
        PoemLine = PoemLine
        'Poem = Poem & PoemLine
        txtPoem = txtPoem + NL & PoemLine
        count = count + 1
    Close #1
    count = 0
    'Me!txtPoem = Poem
End Sub

This is the result I get in the text box:

This is line one of the poem This is line two of the poem This is line three of the poem This is line four of the poem

Except there are two black rectangles seperating each line.

Please Help

1 Solution
Set the textbox's MultiLine property to true :>

billy21Author Commented:
Short and sweet.  Thank you very much.  I would have been coding for hours trying to get around this problem.  I didn't even think to check something so simple.

Thank you again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now