Results 1 to 12 of 12

Thread: Add text1.text into a .txt file

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Add text1.text into a .txt file

    Hi guys,

    Does anybody know how i can make it so that when a user writes some text in a text box and presses command1

    then the text they entered will be added to a .txt file in the app directory and each item will be added on a new line.

    For example if i type hello in text1

    then it will add to a .txt file - hello
    and then if i wrote goodbye it would add goodbye to the .txt file on a new line?

    I hope this makes sense.


    Thanks.
    Jamie

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Add text1.text into a .txt file

    Yes, Open the file for Append.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Add text1.text into a .txt file

    Thanks,

    Could you explain to me how to go about doing this? I don't understand what too do!

    Cheers
    Jamie.

  4. #4
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Add text1.text into a .txt file

    Try this
    Delete it. They just clutter threads anyway.

  5. #5
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Add text1.text into a .txt file

    Code:
    Dim iFileNo As Integer
    Dim sFileText As String
    Open App.Path & "\example.txt" For Append As #iFileNo
         Print #iFileNo, text1.text
    Close #iFileNo
    Make sure that there is a text file called "example.txt" in with the application.
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Add text1.text into a .txt file

    thanks for the reply gamer, How ever i am having an error.

    Saying bad file or number.

    it then highlights - Open App.path & "\example.txt" For Append As #iFileNo

    I have defo put a .txt file in the app directory called example.txt

    What else could cause it to do this?

    Thanks in advance,
    Jamie

  7. #7
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Add text1.text into a .txt file

    oh yeah. i fogot. after Dim sFileText as String, do
    iFileNo = FreeFile
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Add text1.text into a .txt file

    Hi ya mate,

    Sorry but at the moment it seems to be adding the things from the text boz that i add all on the same line in the .txt file.

    Is there a way to make it so each time i press to command button it adds the textbox.text into the txt file but on a differant line?

    Thanks.

  9. #9
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Add text1.text into a .txt file

    It shouldn't do that with Append. Do you have Output instead?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  10. #10
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Add text1.text into a .txt file

    The code that Gamemaster gave you in post #5 (with the small addition in post #7) works just fine. You obviously made no effort to try and join the two to make it work.

  11. #11
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    Re: Add text1.text into a .txt file

    Hi Jamie,

    After modification, can you post your code here so someone can help you...

    Regards
    Veena

  12. #12
    New Member
    Join Date
    Apr 2007
    Posts
    6

    Re: Add text1.text into a .txt file

    'if you use that code your need is ok.

    Private Sub save()
    Dim cfn, cf, fs
    cfn = adress ' you will write here adress like that: c:/test.txt
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.DeleteFile cfn, True
    Set cf = fs.OpenTextFile(cfn, 8, True)
    cf.Write (Text1.Text)
    cf.Close
    End Sub

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