Results 1 to 3 of 3

Thread: [RESOLVED] How to add a name to a textfile??

  1. #1

    Thread Starter
    Member Warad's Avatar
    Join Date
    Feb 2008
    Location
    Netherlands
    Posts
    63

    Resolved [RESOLVED] How to add a name to a textfile??

    Hello, me again

    I have a textfile (c:\data.txt) with a lot of names in it.

    Jack
    Bruce
    Roger
    and so on..

    All these names are loaded in a ListBox (List1) on Form Load.
    I also have a TextBox (txtName) so people can add names to it. When clicking on "Command1" the new name will first be added to the textfile (c:\data.txt) and then it will be added to the ListBox (List1)

    The problem is that the new name thats saved to the textfile (c:\data.txt) is added like this:

    Jack
    Bruce
    RogerNew name

    I want the new name being added like this:

    Jack
    Bruce
    Roger
    New name

    The code i use for saving the new name to the textfile (c:\names.txt) is this:

    'Add new name to textfile
    Open App.Path & "\names.txt" For Append As #1
    Print #1, txtName.Text;
    Close #1

    Can someone tell me what im doing wrong?

    Thanks,
    Warad

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to add a name to a textfile??

    The problem is the semi-colon at the end of the Print line, which is used to say "don't move to the next line".

    The code will work as you want if you simply remove it, eg:
    Code:
    Print #1, txtName.Text

  3. #3

    Thread Starter
    Member Warad's Avatar
    Join Date
    Feb 2008
    Location
    Netherlands
    Posts
    63

    Re: How to add a name to a textfile??

    Thanks geek,

    That solved the problem.

    Warad

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