Save RichTextBox

vb6 Bahrain
  • 14 years ago

    Hi...

    I have the below code, i used it to save text from RichTextBox to notepade:

    Private Sub Save_Click()
    Me.CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
        CommonDialog1.ShowSave

     Me.RichTextBox1.SaveFile Me.CommonDialog1.filename, rtfText
    End Sub

    But some time i want to save the text in RichTextBox because i do not want to load it from the file and i want to make some change in the text then will save it in notepade. 

    please if any body have an idea replay to me...

    Regards

    Bodoora

  • 14 years ago

    Hi Bodoora,

    You can use the same procedure you are using to save the text present in the richtextbox.  I didn't understood why you are so confused about it.  Or if any other problem is there then please be clear.

    Ch. V. Sudhakar

  • 14 years ago

    Hi Sudhakar...

    I create a notepade file (saveout) in drive C: and in this file i want to have the output of all texts that the user saved them, it means that each time user save a text from RichTextBox this file (saveout) will be increase in size. Because each time when we do save will be added to file (saveout) by keeping the previous outfiles saved in it.

    So How can i do this statement with the code above?

    Thanks a lot

    Bodoora

  • 14 years ago

    You could just open the text file for Append which will not overwrite any information but will add to the end of it:

    Private Sub Command1_Click()
    Dim strFullText As String
    strFullText = RichTextBox1.Text
    Open "C:\saveout.txt" For Append As #1
    Print #1, strFullText
    Close #1
    End Sub

    What is the purpose of your program?  If it is keeping some sort of a log you could output some sort of header to the file - Time/Date information etc.

    Private Sub Command1_Click()
    Dim strFulltext, strHeaderInfo, strSeperator As String
    strFulltext = RichTextBox1.Text
    strSeperator = "********************************************"
    strHeaderInfo = CStr(Now()) & vbCrLf & strSeperator & vbCrLf
    Open "C:\saveout.txt" For Append As #1
    Print #1, strHeaderInfo & vbCrLf & strFulltext & vbCrLf & strSeperator & vbcrlf
    Close #1
    End Sub



















  • 14 years ago

    Hi Bodoora,

    I didn't get you.  Please be more clear about your problem.

    Ch. V. Sudhakar

  • 14 years ago

    Hi Sudhakar...

    Thanks for read my message.

    I used the code  was send it by Rob (above) and i solve my problem.

    But if i have any problem in futur i will write !...

    And thanks a lot for all..

    Bodoora 

  • 14 years ago

    Hi Bodoora,

    You are always welcome.

    Bodoora

  • 14 years ago

    Hi...

    I used the below statement to check if there is a file in the same name was saved and if there, the message is apeare, but when i click in No button the window for type the name is close.

    If this statement is true? And what the thing i don't write it to keep the window (save as) open? 

      If filename = filename Then
      MsgBox "This is already save, are U want to replase", vbYesNo
      End If

    thanks

  • 14 years ago

    Hi Bodoora_7,

    I think you want to check whether the file user typed in the saveas dialog exists or not.  For that you need not write any code.  Common dialog has an inbuilt feature for it.

    Before opening the commandialog saveas you give the following code.  It will serve your purpose.

    cd.Flags = cdlOFNOverwritePrompt (Here cd is CommanDialog)

    This will check whether the file exists or not.  If file exists it will ask the user whether to overwrite it or not.  If user says YES then the saveas dialogbox closes.  If user says NO then it remains as it is.

    If possible check all the constants starts with 'cdl' ..... all these constants are of Common Dialog Box only which will give extra features to common dialog.  Better check MSDN for Common Dialog Box Constants.

    Hope this will help you.

    Ch. V. Sudhakar

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves” - Alan Kay