Results 1 to 5 of 5

Thread: Rich Text in Resource File?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    New York City
    Posts
    73
    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??
    Rich

  2. #2
    Lively Member
    Join Date
    Nov 2000
    Posts
    73
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    New York City
    Posts
    73

    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!
    Rich

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    New York City
    Posts
    73
    Just changed the iCtr variable to long and it worked!

    Dim iCtr As Long

    Thanks again!
    Rich

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    New York City
    Posts
    73
    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
    Rich

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