Results 1 to 15 of 15

Thread: Saving Problem

  1. #1

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

    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

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Saving Problem

    Can you post your saving routine?

  3. #3

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

    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:
    1. Private Sub Command1_Click()
    2.    Dim save1 As String
    3. save1 = Dir1.Path & Text1.Text & ".rtf"
    4. Form1.RichTextBox1.SaveFile (save1)
    5. Unload Me
    6. End Sub
    7.  
    8. Private Sub Command2_Click()
    9. Unload Me
    10. End Sub

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Saving Problem

    Add this to your command1_Click

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim save1 As String
    3.     [hl]If Not (Right$(Dir1.Path, 1) = "\") Then
    4.         save1 = Dir1.Path & "\" & Text1.Text & ".rtf"
    5.       Else
    6.         save1 = Dir1.Path & Text1.Text & ".rtf"
    7.     End If[/hl]
    8.     Form1.RichTextBox1.SaveFile (save1)
    9.     Unload Me
    10. End Sub

  5. #5

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

    Re: Saving Problem

    this is now my code

    VB Code:
    1. Private Sub Command1_Click()
    2.    Dim save1 As String
    3.    If Not (Right$(Dir1.Path, 1) = "\") Then
    4.         save1 = Dir1.Path & "\" & Text1.Text & ".rtf"
    5.       Else
    6.         save1 = Dir1.Path & Text1.Text & ".rtf"
    7.     End If
    8. save1 = Dir1.Path & Text1.Text & ".rtf"
    9. Form1.RichTextBox1.SaveFile (save1)
    10. Unload Me
    11. End Sub
    12.  
    13. Private Sub Command2_Click()
    14. Unload Me
    15. End Sub

    And It Still Does The Same Thing

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  7. #7

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

    Re: Saving Problem

    This Is Now My Code
    VB Code:
    1. Private Sub Command1_Click()
    2.    Dim save1 As String
    3.    If Not (Right$(Dir1.Path, 1) = "\") Then
    4.         save1 = Dir1.Path & "\" & Text1.Text & ".rtf"
    5.       Else
    6.         save1 = Dir1.Path & Text1.Text & ".rtf"
    7.     End If
    8. Form1.RichTextBox1.SaveFile (save1)
    9. Unload Me
    10. End Sub
    11.  
    12.  
    13. Private Sub Command2_Click()
    14. Unload Me
    15. 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:
    1. Form1.RichTextBox1.LoadFile (load1)

    highlighted

    the code around this is

    VB Code:
    1. Private Sub Command1_Click()
    2. If Not Text1.Text = "" Then
    3. Dim load1 As String
    4. load1 = Text1.Text
    5. Form1.RichTextBox1.LoadFile (load1)
    6. Unload Me
    7. Else
    8. MsgBox ("No File Selected")
    9. End If
    10. End Sub

    and the text box in the load form shows, C:\Program Filestefesgf.rtf instead of C:\Program Files\tefesgf.rtf

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  9. #9

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

    Re: Saving Problem

    It Is Attached
    Attached Files Attached Files

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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:
    1. Private Sub File1_Click()
    2. Dim Path1 As String
    3. Dim load1 As String
    4. load1 = Text1.Text
    5. Path1 = Dir1.Path
    6. Text1.Text = Path1 [hl]& "\" &[/hl] File1.FileName
    7. End Sub

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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:
    1. Private Sub File1_Click()
    2. Dim Path1 As String
    3. Dim load1 As String
    4. load1 = Text1.Text
    5. Path1 = Dir1.Path
    6. [HL="#FFFF80"]If Not (Right$(Dir1.Path, 1) = "\") Then
    7.         Path1 = Dir1.Path & "\"
    8. End If[/HL]
    9. Text1.Text = Path1 & File1.FileName
    10.  
    11.  
    12. End Sub

  12. #12

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

    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!

  13. #13

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

    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

  14. #14

  15. #15
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Saving Problem

    Change it to

    VB Code:
    1. If (Right$(Path1.Path, 1) = "\") Then
    2.     Text1.Text = Path1.Path & File1.FileName
    3.   Else
    4.     Text1.Text = Path1.Path & "\" & File1.FileName
    5. 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
  •  



Click Here to Expand Forum to Full Width