Is it possible add a rich text file in a resource file and load it into a rich text box on form load? I put a RT file in a resource file and can't figure out how to read it into a rtb. Any suggestions??
Printable View
Is it possible add a rich text file in a resource file and load it into a rich text box on form load? I put a RT file in a resource file and can't figure out how to read it into a rtb. Any suggestions??
hi ,
try this code in new form with richtextbox and command button
1 add the two controls
2 resource file select custom do not change the control
3 copy this code in your form
Public objFile As New Scripting.FileSystemObject 'Object for File
Public objFileRead As Scripting.TextStream 'Object for File Opening/reading/writing
Private Sub Command1_Click()
Dim srtbText() As Byte
Dim iCtr As Integer
Dim sVar As String
Dim sFileName As String
srtbText = LoadResData(101, "custom")
sVar = ""
sFileName = "c:\rtf.txt"
For iCtr = 0 To UBound(srtbText)
sVar = sVar & Chr(srtbText(iCtr))
Next iCtr
'temporary file
Call objFile.CreateTextFile(sFileName, True)
Set objFileRead = objFile.OpenTextFile(sFileName, ForAppending)
objFileRead.Write (sVar)
objFileRead.Close
RichTextBox1.LoadFile (sFileName)
End Sub
if worked well else pass on the code
I see what you're trying to do using a temp file. I tried it and got an overflow at "For iCtr = 0 To UBound(srtbText)"
Any ideas?
Thanks!
Just changed the iCtr variable to long and it worked!
Dim iCtr As Long
Thanks again!
The routing was running REALLY slow (it's a large rich text file). I figured out a lightning fast and simple way of reading a rich text file from a resource file:
Just takes a couple of lines....
Private Sub Command1_Click()
Dim srtbText() As Byte
srtbText = StrConv(LoadResData(101, "CUSTOM"), 64)
RichTextBox1.TextRTF = srtbText
End Sub
Regards,
Rich