|
-
May 26th, 2005, 03:49 PM
#1
Thread Starter
Hyperactive Member
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
Last edited by robcarr2; May 26th, 2005 at 04:34 PM.
-
May 26th, 2005, 03:52 PM
#2
Re: Saving A Text / HTML file
Why doesnt it work? Do you get an error? If yes then what error and on what line?
-
May 26th, 2005, 03:53 PM
#3
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
Last edited by sciguyryan; May 26th, 2005 at 03:57 PM.
-
May 26th, 2005, 04:10 PM
#4
Thread Starter
Hyperactive Member
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
-
May 26th, 2005, 04:11 PM
#5
Thread Starter
Hyperactive Member
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
-
May 26th, 2005, 04:16 PM
#6
Re: Saving A Text / HTML file
 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
-
May 26th, 2005, 04:16 PM
#7
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.
-
May 26th, 2005, 04:18 PM
#8
Re: Saving A Text / HTML file
 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
-
May 26th, 2005, 04:23 PM
#9
Thread Starter
Hyperactive Member
Re: Saving A Text / HTML file
 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
-
May 26th, 2005, 04:25 PM
#10
Re: Saving A Text / HTML file
 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
-
May 26th, 2005, 04:29 PM
#11
Thread Starter
Hyperactive Member
Re: Saving A Text / HTML file
Yes I did it worked, thanks
-
May 26th, 2005, 04:30 PM
#12
Re: Saving A Text / HTML file
 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
-
May 26th, 2005, 05:34 PM
#13
Re: Saving A Text / HTML file {Resolved}
This will save it as a text file
VB Code:
rtbReceipt.SaveFile App.Path & "\LastInvoice.rtf",1
-
May 26th, 2005, 05:39 PM
#14
Re: Saving A Text / HTML file {Resolved}
 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 
Cheers,
RyanJ
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
|