|
-
Oct 7th, 2006, 03:22 PM
#1
Thread Starter
Addicted Member
[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
-
Oct 7th, 2006, 04:56 PM
#2
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:
[B]'Writing 2 files under same event[/B]
RichTextBox1.SaveFile App.Path & "\test.txt", rtfText
RichTextBox2.SaveFile App.Path & "\testfirst.txt", rtfText
'Just wrote 2 files
'End Event
[b]'Reading 2 files under same event[/b]
RichTextBox1.LoadFile App.Path & "\test.txt", rtfText
RichTextBox2.LoadFile App.Path & "\testfirst.txt", rtfText
-
Oct 8th, 2006, 05:25 AM
#3
Thread Starter
Addicted Member
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
-
Oct 8th, 2006, 10:42 AM
#4
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:
On Error GoTo out
With CommonDialog1
.CancelError = True
.Filter = "Text files (*.txt)|*.txt"
.DialogTitle = "Save the file..."
.ShowSave
If .FileName <> "" Then
RichTextBox1.SaveFile .FileName, rtfText
RichTextBox2.SaveFile Left(.FileName, Len(.FileName) - 4) & "first.txt", rtfText
End If
End With
Exit Sub
out:
-
Oct 9th, 2006, 04:50 AM
#5
Thread Starter
Addicted Member
-
Oct 9th, 2006, 04:55 AM
#6
Frenzied Member
Re: save text
 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
-
Oct 9th, 2006, 05:16 AM
#7
Re: save text
 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()
-
Oct 9th, 2006, 03:56 PM
#8
Thread Starter
Addicted Member
Re: [RESOLVED] save text
thanks gavio it's exactly what i need
-
Oct 9th, 2006, 04:21 PM
#9
Re: [RESOLVED] save text
 Originally Posted by om-yousif
thanks gavio it's exactly what i need

Glad to help you!
-
Nov 1st, 2006, 09:53 AM
#10
Member
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:
With CommonDialog1
.CancelError = True
.Filter = "Text files (*.txt)|*.txt"
.DialogTitle = "Save the file..."
.ShowSave
If .filename <> "" Then
RichTextBox1.SaveFile .filename, rtfText
RichTextBox2.SaveFile Left(.filename, Len(.filename) - 4) & "first.txt", rtfText
End If
End With
So how can I correct this problem?
-
Nov 1st, 2006, 10:01 AM
#11
Re: [RESOLVED] save text
The second file can be empty only if RichTextBox2 is empty... Hmm... can you zip and post the project?
-
Nov 1st, 2006, 10:31 AM
#12
Member
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 ?
-
Nov 1st, 2006, 10:44 AM
#13
Re: [RESOLVED] save text
Add this before the .ShowSave method:
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|