Results 1 to 10 of 10

Thread: saving to a text file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281
    I have a text box and a command button.

    How can I have it so that, when the command button is pressed,
    what ever is typed in the text box will be saved to the top line of
    a file "C:\windows\desktop\orders.txt"?

    I don't want to erase what has already been in the text file, just
    to add the new information to it.

    Thanks for any help!

    I.

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Try this:
    Code:
    ' Append to file
    Dim FileNumber
    FileNumber = FreeFile
    Open "C:\Windows\desktop\orders.txt" For Append As FileNumber
    Print #FileNumber, Text1.Text
    Close FileNumber

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Oh sorry, I just re-read you wanted it at the top of the file...hmmm...you'll have to read in the existing file contents, append Text1.Text to the beginning then output the result, overwriting what is already there.

  4. #4
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Use For Append:

    Code:
    Open "C:\windows\desktop\orders.txt" For Append As #1
    Put #1, , "String"
    ...


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  5. #5
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Originally posted by chrisjk
    Oh sorry, I just re-read you wanted it at the top of the file...hmmm...you'll have to read in the existing file contents, append Text1.Text to the beginning then output the result, overwriting what is already there.
    Er...No. The For Can take:

    • Append
    • Binary
    • Input
    • Output
    • Rendom


    So append is very easy.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  6. #6
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    He wants to append to the beginning. Append only adds to the end of the file

  7. #7
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    OK, then you're right.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  8. #8
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    I know

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    Thumbs up

    Thanks for your help - it did pretty much what I wanted.

    But one important development is necessary. How can I program it so that, whatever text is selected in the text box (as opposed to all the text in the box) is added to the text file?

    Actually, I think I have it....sorry about that. It's Text1.Seltext, me thinks.

    E.g:

    ' Append to file
    Dim FileNumber
    FileNumber = FreeFile
    Open "C:\Windows\desktop\orders.txt" For Append As FileNumber
    Print #FileNumber, Text1.Seltext
    Close FileNumber

    But how can I save it to the top of the file?

    Thanks!

  10. #10
    demirc
    Guest
    Use

    Seek #1,x

    to append at the top (x=1)
    or
    where ever you wish (x=whatever)

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