Results 1 to 15 of 15

Thread: Rich Text Box Save/Load

  1. #1

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Rich Text Box Save/Load

    What Is The Code So That When I Press The Save Button (called: mnuSave)

    it saves what is in the rich text box (called: RichTextBox1) into a place specified

    and What Is The Code So That When I Press The Load Button (called: mnuLoad)

    it Loads a specified .rtf into the rich text box (called: RichTextBox1)

    Thanx, Lavarock09

  2. #2
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Rich Text Box Save/Load

    VB Code:
    1. dim strSave As String
    2.  
    3. Private Sub mnuSave_Click(Index As Integer)
    4.  
    5. strSave = richtextbox1.Text
    6.  
    7. Open C:\location For Append As #1
    8.     Print #1, strSave
    9. Close #1
    10.  
    11. End Sub
    12.  
    13. Private Sub mnuLoad_Click(Index As Integer)
    14.  
    15. Open C:\location for Input As #1
    16.      Input #1, strSave
    17. Close #1
    18.  
    19. richtextbox.Text = strSave
    20.  
    21. End Sub

  3. #3

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Rich Text Box Save/Load

    with this i get the error

    Compile Error: Procedure Declaration Does Not Match Desctiption Of Event Having The Same Name
    with this line highlighted on both load and save ,"Private Sub mnuLoad_Click(Index As Integer"

    And The Lines

    Open C:\location for Input As #1
    on the load script

    and

    Open C:\location For Append As #1
    on the save script

    are in Red

    Thanx For Yor Help

  4. #4
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Rich Text Box Save/Load

    to save a RTB you need to do it this way to save the formatting:
    VB Code:
    1. Private Sub Form_Load()
    2.     RichTextBox.SaveFile ("C:\yay.txt")
    3. End Sub

    To save a normal textbox/load it do it like so:

    dim ff as integer
    ff=freefile
    VB Code:
    1. Open "C:\yay.txt" for input as #FF'opens
    2. text1.text = input$(LOF(FF),FF)
    3. close #ff
    VB Code:
    1. Open "C:\yay.txt" For Append As #ff'writes to file
    2. Print, text1.text
    3. close #ff

  5. #5
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Rich Text Box Save/Load

    Oh I might have written the subs for your save buttons incorrectly... just open the code for your mnuSave and mnuLoad and put the code in there

    As for C:\Directory you must put a directory in there for example this will save it to your desktop

    VB Code:
    1. Open C:\Desktop for Append as #1

  6. #6
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Rich Text Box Save/Load

    no it wont..Thats saving a textfile as your desktop! you need to add a file name and type after that.

    Open "C:\Desktop\yay.txt" for Append as #1

    it also must be in quotes

  7. #7

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Rich Text Box Save/Load

    this one {QUOTE}Open C:\Desktop for Append as #1[/QUOTE]
    still doesn't work

    but |2eM!x's Does Work, but how do i make it so they can specify where to save

  8. #8
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Rich Text Box Save/Load

    do you want to use commondialog? (like when you click on file save in any program that box will pop up) or do you just want them to be able to type a filepath.

    For commondialog:
    VB Code:
    1. Private Sub Form_Load() 'Opens
    2. Dim ff As Integer
    3.     With CommonDialog
    4.         .FileName = vbNullString
    5.         .InitDir = "C:"
    6.         .ShowOpen
    7.             If Len(.FileName) > 0 Then
    8.             ff = FreeFile
    9.                 Open .FileName For Input As #ff
    10.                     RichTextBox1.Text = Input(LOF(ff), ff)
    11.                 Close #ff
    12.             End If
    13.    End With
    14. End Sub
    VB Code:
    1. Private Sub Form_Load()'to save
    2. Dim ff As Integer
    3.     With CommonDialog
    4.         .FileName = vbNullString
    5.         .InitDir = "C:"
    6.         .ShowSave
    7.             If Len(.FileName) > 0 Then
    8.             ff = FreeFile
    9.                 Open .FileName For Output As #ff
    10.                     Print #ff, RichTextBox1.Text
    11.                 Close #ff
    12.             End If
    13.     End With
    14. End Sub

    Without commondialog, use a textbox to specify file placement,

    VB Code:
    1. Open text1.text for input as #FF'opens
    2. text1.text = input$(LOF(FF),FF)
    3. close #ff

  9. #9

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Rich Text Box Save/Load

    for saving, i have made a commondialog

    and it says in the code

    .FileName =

    but i get the error "Method Or Data Member Not Found"

  10. #10
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Rich Text Box Save/Load

    .filename = vbnullstring

  11. #11

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Rich Text Box Save/Load

    thanx a lot guys, but i fixed it (only the load, but i think i have nearly done save) with another code i typed myself

    one thing though, how do you make a file list only display files with a certain extension, in my case the extension rtf

  12. #12
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Rich Text Box Save/Load

    .Filter = "RTF files (*.rtf)|*.rtf"

    put this before your .showsave or .showload

  13. #13

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Rich Text Box Save/Load

    i dont have that i have

    this code for a file and directory list

    VB Code:
    1. Private Sub Dir1_Change()
    2. File1.Path = Dir1.Path
    3. Dim Path1 As String
    4. Path1 = Dir1.Path
    5. End Sub
    6.  
    7. Private Sub File1_Click()
    8. Dim Path1 As String
    9. Path1 = Dir1.Path
    10. Text1.Text = Path1 & File1.FileName
    11. End Sub

  14. #14
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Rich Text Box Save/Load

    well that isnt commondialog...

  15. #15

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Rich Text Box Save/Load

    i know it isn't i changed them

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