|
-
Jun 17th, 2005, 11:17 AM
#1
Thread Starter
Lively Member
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
-
Jun 17th, 2005, 11:28 AM
#2
Fanatic Member
Re: Rich Text Box Save/Load
VB Code:
dim strSave As String
Private Sub mnuSave_Click(Index As Integer)
strSave = richtextbox1.Text
Open C:\location For Append As #1
Print #1, strSave
Close #1
End Sub
Private Sub mnuLoad_Click(Index As Integer)
Open C:\location for Input As #1
Input #1, strSave
Close #1
richtextbox.Text = strSave
End Sub
-
Jun 17th, 2005, 11:34 AM
#3
Thread Starter
Lively Member
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
-
Jun 17th, 2005, 11:39 AM
#4
Re: Rich Text Box Save/Load
to save a RTB you need to do it this way to save the formatting:
VB Code:
Private Sub Form_Load()
RichTextBox.SaveFile ("C:\yay.txt")
End Sub
To save a normal textbox/load it do it like so:
dim ff as integer
ff=freefile
VB Code:
Open "C:\yay.txt" for input as #FF'opens
text1.text = input$(LOF(FF),FF)
close #ff
VB Code:
Open "C:\yay.txt" For Append As #ff'writes to file
Print, text1.text
close #ff
-
Jun 17th, 2005, 11:39 AM
#5
Fanatic Member
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:
Open C:\Desktop for Append as #1
-
Jun 17th, 2005, 11:45 AM
#6
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
-
Jun 17th, 2005, 11:48 AM
#7
Thread Starter
Lively Member
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
-
Jun 17th, 2005, 12:00 PM
#8
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:
Private Sub Form_Load() 'Opens
Dim ff As Integer
With CommonDialog
.FileName = vbNullString
.InitDir = "C:"
.ShowOpen
If Len(.FileName) > 0 Then
ff = FreeFile
Open .FileName For Input As #ff
RichTextBox1.Text = Input(LOF(ff), ff)
Close #ff
End If
End With
End Sub
VB Code:
Private Sub Form_Load()'to save
Dim ff As Integer
With CommonDialog
.FileName = vbNullString
.InitDir = "C:"
.ShowSave
If Len(.FileName) > 0 Then
ff = FreeFile
Open .FileName For Output As #ff
Print #ff, RichTextBox1.Text
Close #ff
End If
End With
End Sub
Without commondialog, use a textbox to specify file placement,
VB Code:
Open text1.text for input as #FF'opens
text1.text = input$(LOF(FF),FF)
close #ff
-
Jun 17th, 2005, 12:08 PM
#9
Thread Starter
Lively Member
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"
-
Jun 17th, 2005, 12:24 PM
#10
Re: Rich Text Box Save/Load
-
Jun 17th, 2005, 12:31 PM
#11
Thread Starter
Lively Member
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
-
Jun 17th, 2005, 12:33 PM
#12
Re: Rich Text Box Save/Load
.Filter = "RTF files (*.rtf)|*.rtf"
put this before your .showsave or .showload
-
Jun 17th, 2005, 12:35 PM
#13
Thread Starter
Lively Member
Re: Rich Text Box Save/Load
i dont have that i have
this code for a file and directory list
VB Code:
Private Sub Dir1_Change()
File1.Path = Dir1.Path
Dim Path1 As String
Path1 = Dir1.Path
End Sub
Private Sub File1_Click()
Dim Path1 As String
Path1 = Dir1.Path
Text1.Text = Path1 & File1.FileName
End Sub
-
Jun 17th, 2005, 12:40 PM
#14
Re: Rich Text Box Save/Load
well that isnt commondialog...
-
Jun 17th, 2005, 12:44 PM
#15
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|