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:
Private Sub mnuFileSave_Click()
Dim sfilename As Long
On Error GoTo Err
CommonDialog1.Filter = "Text Document|*.txt |HTML Document | *.htm;*.html"
CommonDialog1.ShowSave
sfilename = CommonDialog1.FileName
Open sfilename For Output As #1
Write #1, RichTextMain1.Text
Close #1
Err:
End Sub
Re: Saving A Text / HTML file
Why doesnt it work? Do you get an error? If yes then what error and on what line?
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:
Private Sub mnuFileSave_Click()
Dim sfilename As Long
Dim intFree As Integer
intFree = FreeFile
On Error GoTo Err
CommonDialog1.Filter = "Text Document|*.txt |HTML Document | *.htm;*.html"
CommonDialog1.ShowSave
sfilename = CommonDialog1.FileName
Open sfilename For Binary Access Write As #intFree
Put #intFree, , RichTextMain1.Text
Close #intFree
Err:
End Sub
Cheers,
RyanJ
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
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:
sfilename = CommonDialog1.FileName
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:
sfilename = CommonDialog1.FileName
Hits head against wall...
Why didn't I see that?
Try this:
VB Code:
Private Sub mnuFileSave_Click()
Dim sfilename As String
Dim intFree As Integer
intFree = FreeFile
On Error GoTo Err
CommonDialog1.Filter = "Text Document|*.txt |HTML Document | *.htm;*.html"
CommonDialog1.ShowSave
sfilename = CommonDialog1.FileName
Open sfilename For Binary Access Write As #intFree
Put #intFree, , RichTextMain1.Text
Close #intFree
Err:
End Sub
Cheers,
RyanJ
Re: Saving A Text / HTML file
The RTB can save a file.
VB Code:
rtbReceipt.SaveFile App.Path & "\LastInvoice.rtf"
It preserves formatting, and you can open it in word.
Re: Saving A Text / HTML file
Quote:
Originally Posted by dglienna
The RTB can save a file.
VB Code:
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
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 :)
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
Re: Saving A Text / HTML file
Yes I did it worked, thanks :)
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
Re: Saving A Text / HTML file {Resolved}
This will save it as a text file
VB Code:
rtbReceipt.SaveFile App.Path & "\LastInvoice.rtf",1
Re: Saving A Text / HTML file {Resolved}
Quote:
Originally Posted by dglienna
This will save it as a text file
VB Code:
rtbReceipt.SaveFile App.Path & "\LastInvoice.rtf",1
I never knew it had a second perameter!
Thanks for the tip dglienna :D
Cheers,
RyanJ