Results 1 to 13 of 13

Thread: [RESOLVED] save text

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Resolved [RESOLVED] save text

    I have two texts

    when I save one of them as a notepad file for example and name it as (text.txt ) the second text should be saved automatically as (textfirst.txt) in the same directory

    I mean I save one and enter a name for t the second should be saved with the same name followed by word (first)

    And how can I open both of them and load them in the richtext boxes by choosing one file from an open window

    Simply if I choose the file (text.txt) to be opened and loaded in a richtext box automatically file (textfirst.txt) well be laoded in another richtext box


    thanks

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: save text

    Just open the 2 files one after another for reading/writing.
    psuedocode only and since you have mentioned use of Richtextbox, I am answer accordingly:
    VB Code:
    1. [B]'Writing 2 files under same event[/B]
    2. RichTextBox1.SaveFile App.Path & "\test.txt", rtfText
    3.  
    4. RichTextBox2.SaveFile App.Path & "\testfirst.txt", rtfText
    5.  
    6. 'Just wrote 2 files
    7. 'End Event
    8.  
    9. [b]'Reading 2 files under same event[/b]
    10. RichTextBox1.LoadFile App.Path & "\test.txt", rtfText
    11.  
    12. RichTextBox2.LoadFile App.Path & "\testfirst.txt", rtfText
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: save text

    may be i didn't expailn it very well

    i mean that they two texts in richtext boxs
    i need to save them in notepad by leting user to save one of them only ,the second well be saved automatically

    user should enter the name of the file to be saved as we do in Ms Word
    and the second well be of the same name followed by (fiist)

    *name of file is not fixed it,s changing each time

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: save text

    They try the following. Go to menu Project>>Components>>... and add a MS Common Dialog Control. Now add one to your form (plus a CommandButton) and try this:
    VB Code:
    1. On Error GoTo out
    2.     With CommonDialog1
    3.         .CancelError = True
    4.         .Filter = "Text files (*.txt)|*.txt"
    5.         .DialogTitle = "Save the file..."
    6.         .ShowSave
    7.             If .FileName <> "" Then
    8.                 RichTextBox1.SaveFile .FileName, rtfText
    9.                 RichTextBox2.SaveFile Left(.FileName, Len(.FileName) - 4) & "first.txt", rtfText
    10.             End If
    11.     End With
    12.         Exit Sub
    13. out:

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: save text

    Yes gavio it's working thanks



    what about opening and loading the two texts

  6. #6
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: save text

    Quote Originally Posted by om-yousif
    Yes gavio it's working thanks



    what about opening and loading the two texts
    should work for opening.. i dun have vb to test though
    On Error GoTo out
    With CommonDialog1
    .CancelError = True
    .Filter = "Text files (*.txt)|*.txt"
    .DialogTitle = "Open the file..."
    .ShowOpen
    If .FileName <> "" Then
    RichTextBox1.LoadFile .FileName, rtfText
    End If
    End With
    Exit Sub

  7. #7
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: save text

    Quote Originally Posted by om-yousif
    Yes gavio it's working thanks



    what about opening and loading the two texts
    It's reverse. Use LoadFile() instead of SaveFile()

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: [RESOLVED] save text

    thanks gavio it's exactly what i need


  9. #9
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [RESOLVED] save text

    Quote Originally Posted by om-yousif
    thanks gavio it's exactly what i need

    Glad to help you!

  10. #10
    Member
    Join Date
    Aug 2006
    Location
    Arabian Gulf
    Posts
    46

    Question Re: [RESOLVED] save text

    Hi gavio...
    I used your code for save, it work but if I reload the file and make chang in RichTextBox1 and save it with the same name,I have problem it is the fist file (NotePade) save in it what have in RichTextBox2 and the second file is empty.
    VB Code:
    1. With CommonDialog1
    2.         .CancelError = True
    3.         .Filter = "Text files (*.txt)|*.txt"
    4.         .DialogTitle = "Save the file..."
    5.         .ShowSave
    6.             If .filename <> "" Then
    7.                RichTextBox1.SaveFile .filename, rtfText
    8.                RichTextBox2.SaveFile Left(.filename, Len(.filename) - 4) & "first.txt", rtfText
    9.                
    10.             End If
    11.     End With
    So how can I correct this problem?

  11. #11
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [RESOLVED] save text

    The second file can be empty only if RichTextBox2 is empty... Hmm... can you zip and post the project?

  12. #12
    Member
    Join Date
    Aug 2006
    Location
    Arabian Gulf
    Posts
    46

    Question Re: [RESOLVED] save text

    Thanks you right..
    but if i write the same name, how can i do the message that appear when the file have the same name ?

  13. #13
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [RESOLVED] save text

    Add this before the .ShowSave method:
    VB Code:
    1. CommonDialog1.Flags = cdlOFNOverwritePrompt

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