Results 1 to 5 of 5

Thread: How to add text to RTF textbox at runtime?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    Question How to add text to RTF textbox at runtime?

    How do I add a series of data to a RTFtextbox at runtime?

    e.g. of what I want
    Name Address Age Salary

    13/03/2002

    John Creek hill 25 30,000
    Mary Valley West 39 35,000

    Total ===> 65,000
    ___________________________________________


    Example of how I am trying to code it

    rtb1.Font.Bold = True
    rtb1.Font.Underline = True
    rtb1.Text = "Name " & vbTab & "Addrress " & vbTab & "Age" & vbTab & " Salary

    rtb1.Font.Bold = False
    rtb1.Font.Underline = False
    rtb1.Font.Italic = True
    rtb1.text = Date()

    rtb1.Font.Italic = False

    For i = LBound(myArray) to UBound(myArray)
    rtb1.Text = name(myArray) & vbTab & address(myArray) ........
    next i
    ________________________________________________

    I know when I do rtb1.Font.Underline = False I am setting this attribute False for the whole textbox, but how do I vary it.

    Note:
    My array is populated with data read for a file. The size of this file will vary but will generally be in excess of 2000 lines.

    Hope someone can help.
    Mel

  2. #2
    Fanatic Member
    Join Date
    Jan 2001
    Posts
    574
    Use the selstart

    Like
    rtf1.selstart = 10 'want to start at the 10 character
    rtf1.sellength = 5 'take 5 characters
    rtf1.selbold = True 'only make this 5 characters bold

    Hope it helps

  3. #3
    Lively Member
    Join Date
    Oct 2001
    Posts
    125
    the formatting caps of the RTFBox refer to the currently selected (-->highlighted) parts of the text. Thus, you have to set SelStart and SelLength according to your requirements and then
    Code:
    with RTFBox1
      .SelStart=138         'Start Selection at Character 138)
      .SelLength=10        'Length of selected Substring=10
      .SelBold=True         'Make Selection Bold
      .SelUnderline=True 'Underline the stuff
    end with
    Same goes with Fontsize, Font, Color, Italics etc..

    Then save everything using RTFBox1.Savefile "C:\FILENAME.RTF",0

    Hope that finally helps, since this is your 3.attempt or so?

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    My problem is I dont' know how many characters or lines there will be. I am reading the data from an external file, and looping through it until EOF is reached.

    Forget it, I'll find another way around it.

    Thanks anyway.
    Mel

  5. #5
    Lively Member
    Join Date
    Oct 2001
    Posts
    125
    If you are reading data, like from a data base, and either the strings end with CRLF or you have some other possibility of identifying the end of a record, then you should be able to do your formatting line-by-line or string-by-string. You have to keep track of the number of characters already written, then you could set selstart and length accordingly.

    Another workaround comes to mind (albeit a bit dirty):
    Read your data, put a full record into another (small, temorary) RTFBox, do your formatting and add the contents to the final RTFBox. Just set .Visible to False and no one 'll ever find out.

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