Results 1 to 14 of 14

Thread: Saving A Text / HTML file {Resolved}

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    346

    Resolved Saving A Text / HTML file {Resolved}

    Hey I want to save a file to either text or html frm a richtext box, here is my code i have written that wont work

    VB Code:
    1. Private Sub mnuFileSave_Click()
    2. Dim sfilename As Long
    3. On Error GoTo Err
    4. CommonDialog1.Filter = "Text Document|*.txt |HTML Document | *.htm;*.html"
    5. CommonDialog1.ShowSave
    6. sfilename = CommonDialog1.FileName
    7. Open sfilename For Output As #1
    8. Write #1, RichTextMain1.Text
    9. Close #1
    10. Err:
    11. End Sub
    Last edited by robcarr2; May 26th, 2005 at 04:34 PM.

    Microsoft gives you Windows, Linux gives you the whole house!


    I am who I am because of who we all are.


    We have just gotten a wake up call from the Nintendo generation.

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Saving A Text / HTML file

    Why doesnt it work? Do you get an error? If yes then what error and on what line?

  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Saving A Text / HTML file

    Did you get ane error messages? If yes what was it (Or were they)?

    I have an idea, try this:

    VB Code:
    1. Private Sub mnuFileSave_Click()
    2.     Dim sfilename As Long
    3.     Dim intFree As Integer
    4.     intFree = FreeFile
    5.     On Error GoTo Err
    6.     CommonDialog1.Filter = "Text Document|*.txt |HTML Document | *.htm;*.html"
    7.     CommonDialog1.ShowSave
    8.     sfilename = CommonDialog1.FileName
    9.     Open sfilename For Binary Access Write As #intFree
    10.         Put #intFree, , RichTextMain1.Text
    11.     Close #intFree
    12.     Err:
    13. End Sub


    Cheers,

    RyanJ
    Last edited by sciguyryan; May 26th, 2005 at 03:57 PM.
    My Blog.

    Ryan Jones.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    346

    Re: Saving A Text / HTML file

    Tried that and it does the same as what happens at moment, no error message, but doesnt save file

    Microsoft gives you Windows, Linux gives you the whole house!


    I am who I am because of who we all are.


    We have just gotten a wake up call from the Nintendo generation.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    346

    Re: Saving A Text / HTML file

    i took the on error goto err: and it said 'Type Mismatch' when i tried saving and highlighted this

    VB Code:
    1. sfilename = CommonDialog1.FileName

    Microsoft gives you Windows, Linux gives you the whole house!


    I am who I am because of who we all are.


    We have just gotten a wake up call from the Nintendo generation.

  6. #6
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Saving A Text / HTML file

    Quote Originally Posted by robcarr2
    i took the on error goto err: and it said 'Type Mismatch' when i tried saving and highlighted this

    VB Code:
    1. sfilename = CommonDialog1.FileName

    Hits head against wall...

    Why didn't I see that?

    Try this:

    VB Code:
    1. Private Sub mnuFileSave_Click()
    2.     Dim sfilename As String
    3.     Dim intFree As Integer
    4.     intFree = FreeFile
    5.     On Error GoTo Err
    6.     CommonDialog1.Filter = "Text Document|*.txt |HTML Document | *.htm;*.html"
    7.     CommonDialog1.ShowSave
    8.     sfilename = CommonDialog1.FileName
    9.     Open sfilename For Binary Access Write As #intFree
    10.         Put #intFree, , RichTextMain1.Text
    11.     Close #intFree
    12.     Err:
    13. End Sub

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Saving A Text / HTML file

    The RTB can save a file.

    VB Code:
    1. rtbReceipt.SaveFile App.Path & "\LastInvoice.rtf"

    It preserves formatting, and you can open it in word.

  8. #8
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Saving A Text / HTML file

    Quote Originally Posted by dglienna
    The RTB can save a file.

    VB Code:
    1. rtbReceipt.SaveFile App.Path & "\LastInvoice.rtf"

    It preserves formatting, and you can open it in word.

    One problem, that is a bad thing if you want to save it as a plain text file or HTML file which i think is what is trying to be done here

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    346

    Re: Saving A Text / HTML file

    Quote Originally Posted by sciguyryan
    One problem, that is a bad thing if you want to save it as a plain text file or HTML file which i think is what is trying to be done here

    Cheers,

    RyanJ
    I am trying to save as plain text or html but thanks for the info on rtf files as i was also unsure about that

    Microsoft gives you Windows, Linux gives you the whole house!


    I am who I am because of who we all are.


    We have just gotten a wake up call from the Nintendo generation.

  10. #10
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Saving A Text / HTML file

    Quote Originally Posted by robcarr2
    I am trying to save as plain text or html but thanks for the info on rtf files as i was also unsure about that

    Did you try the last code I posted?

    It looks like you were trying to return a string into a long (This can only be done in pointers, not available in VB anyway so no need to worry about it... )

    RyanJ
    My Blog.

    Ryan Jones.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    346

    Re: Saving A Text / HTML file

    Yes I did it worked, thanks

    Microsoft gives you Windows, Linux gives you the whole house!


    I am who I am because of who we all are.


    We have just gotten a wake up call from the Nintendo generation.

  12. #12
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Saving A Text / HTML file

    Quote Originally Posted by robcarr2
    Yes I did it worked, thanks

    Great!

    Just remember to edit your origina post and add the green checkmark as its icon and add [Resolved] to yuor post title

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Saving A Text / HTML file {Resolved}

    This will save it as a text file
    VB Code:
    1. rtbReceipt.SaveFile App.Path & "\LastInvoice.rtf",1

  14. #14
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Saving A Text / HTML file {Resolved}

    Quote Originally Posted by dglienna
    This will save it as a text file
    VB Code:
    1. rtbReceipt.SaveFile App.Path & "\LastInvoice.rtf",1

    I never knew it had a second perameter!

    Thanks for the tip dglienna

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

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