Jun 19th, 2005, 11:07 AM
#1
Thread Starter
Lively Member
Saving Problem
Hi All,
I am saving text in a rich text box by using, drive lists, directory lists and a file list...
and i thought it all worked fine, until
when i tried to save a file in somewhere like, C:\Program Files\test1.rtf it worked, but When i go to C:\Program Files\Microsoft\test1.rtf
It saved it in C:\Program Files with the file name Microsofttest1.rtf
is there a way to fix this
Thanx
Lavarock09
Jun 19th, 2005, 11:16 AM
#2
Re: Saving Problem
Can you post your saving routine?
Jun 19th, 2005, 11:20 AM
#3
Thread Starter
Lively Member
Re: Saving Problem
1. You Click Save
2. You Choose Your Drive, Then Directory
3.You Click Ok,
4. The Rich Text Box Shows The Text
Code For Save Form
VB Code:
Private Sub Command1_Click()
Dim save1 As String
save1 = Dir1.Path & Text1.Text & ".rtf"
Form1.RichTextBox1.SaveFile (save1)
Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Jun 19th, 2005, 11:24 AM
#4
Re: Saving Problem
Add this to your command1_Click
VB Code:
Private Sub Command1_Click()
Dim save1 As String
[hl]If Not (Right$(Dir1.Path, 1) = "\") Then
save1 = Dir1.Path & "\" & Text1.Text & ".rtf"
Else
save1 = Dir1.Path & Text1.Text & ".rtf"
End If[/hl]
Form1.RichTextBox1.SaveFile (save1)
Unload Me
End Sub
Jun 19th, 2005, 11:31 AM
#5
Thread Starter
Lively Member
Re: Saving Problem
this is now my code
VB Code:
Private Sub Command1_Click()
Dim save1 As String
If Not (Right$(Dir1.Path, 1) = "\") Then
save1 = Dir1.Path & "\" & Text1.Text & ".rtf"
Else
save1 = Dir1.Path & Text1.Text & ".rtf"
End If
save1 = Dir1.Path & Text1.Text & ".rtf"
Form1.RichTextBox1.SaveFile (save1)
Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
And It Still Does The Same Thing
Jun 19th, 2005, 11:32 AM
#6
Re: Saving Problem
Sorry, I should have said replace the save1= line with that block. In your code now it sets save1 and then sets it back to what you had before so it's no different
Take out the save1 = line after the If block.
Jun 19th, 2005, 11:37 AM
#7
Thread Starter
Lively Member
Re: Saving Problem
This Is Now My Code
VB Code:
Private Sub Command1_Click()
Dim save1 As String
If Not (Right$(Dir1.Path, 1) = "\") Then
save1 = Dir1.Path & "\" & Text1.Text & ".rtf"
Else
save1 = Dir1.Path & Text1.Text & ".rtf"
End If
Form1.RichTextBox1.SaveFile (save1)
Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
But Now When i Go To Load, It Gives A Debug Message And In The Loading Form It has the line
VB Code:
Form1.RichTextBox1.LoadFile (load1)
highlighted
the code around this is
VB Code:
Private Sub Command1_Click()
If Not Text1.Text = "" Then
Dim load1 As String
load1 = Text1.Text
Form1.RichTextBox1.LoadFile (load1)
Unload Me
Else
MsgBox ("No File Selected")
End If
End Sub
and the text box in the load form shows, C:\Program Filestefesgf.rtf instead of C:\Program Files\tefesgf.rtf
Jun 19th, 2005, 11:42 AM
#8
Re: Saving Problem
I'm not really sure why that would be.
Can you post your project? If you zip it up I'll take a look at it.
Jun 19th, 2005, 11:45 AM
#9
Thread Starter
Lively Member
Re: Saving Problem
Attached Files
Jun 19th, 2005, 11:56 AM
#10
Re: Saving Problem
OK. Some suggestions
Use Option Explicit at the top of all your forms/modues to ensure you name your variabls and to catch typos Build with full compile and don't use background compile (Tools->Options->General) so that you catch all the bugs every time you run the app. Instead of making forms for everything, you can use the command dialog control to provide Windows' own Open/Save boxes, and you can use a MsgBox for the Yes/No/Cancel prompt.
That having been said, here's how to fix your problem from post #7:
VB Code:
Private Sub File1_Click()
Dim Path1 As String
Dim load1 As String
load1 = Text1.Text
Path1 = Dir1.Path
Text1.Text = Path1 [hl]& "\" &[/hl] File1.FileName
End Sub
Jun 19th, 2005, 12:01 PM
#11
Re: Saving Problem
There are a buch of ocx's and a bas file missing from your zip file but I think this is your problem. Add the highlighted code to Form6.
VB Code:
Private Sub File1_Click()
Dim Path1 As String
Dim load1 As String
load1 = Text1.Text
Path1 = Dir1.Path
[HL="#FFFF80"]If Not (Right$(Dir1.Path, 1) = "\") Then
Path1 = Dir1.Path & "\"
End If[/HL]
Text1.Text = Path1 & File1.FileName
End Sub
Jun 19th, 2005, 12:03 PM
#12
Thread Starter
Lively Member
Re: Saving Problem
thanx now that works,
this isn't a problem but it makes it look nicer,
when i load a file from the directory C:\ on its own
it says in the textbox C:\\ File1.rtf
is there a way to stop this,
but thanx for all your help!
Jun 19th, 2005, 12:04 PM
#13
Thread Starter
Lively Member
Re: Saving Problem
THIS IS IN REPLY TO POST #10
thanx now that works,
this isn't a problem but it makes it look nicer,
when i load a file from the directory C:\ on its own
it says in the textbox C:\\ File1.rtf
is there a way to stop this,
but thanx for all your help!x
Sorry For Double Posting
Jun 19th, 2005, 12:09 PM
#14
Re: Saving Problem
Are you sure it still does because when I do it it doesn't.
Jun 19th, 2005, 12:14 PM
#15
Re: Saving Problem
Change it to
VB Code:
If (Right$(Path1.Path, 1) = "\") Then
Text1.Text = Path1.Path & File1.FileName
Else
Text1.Text = Path1.Path & "\" & File1.FileName
End If
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