[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Richtextbox problem about SelBold

Posted on 2006-03-20
5
Medium Priority
?
360 Views
Last Modified: 2008-02-26
Hi, the resulting text supposed to be
Text is <b>Highlighted</b> No Highlighted
(<b>..</b> is the portion that bold)
But the result appeared to be nothing is bold, what is the problem?

Followed is the code: (rtf is the name of richtextbox)

Private Sub Command1_Click()
Dim iStart As Integer
rtf.Text = "Text is "
iStart = Len(rtf.Text)
rtf.Text = rtf.Text & "Highlighted"
rtf.SelStart = iStart
rtf.SelLength = Len(rtf.Text) - iStart
rtf.SelBold = True
rtf.Text = rtf.Text & " No Highlighted"
End Sub
0
Comment
Question by:william007
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Preece
ID: 16235629
What is happening is that "Highlighted" is set to bold, but the next line of code resets the formatting

Private Sub Command1_Click()
Dim iStart As Integer
rtf.Text = "Text is "
iStart = Len(rtf.Text)
rtf.Text = rtf.Text & "Highlighted"
rtf.SelStart = iStart
rtf.SelLength = Len(rtf.Text) - iStart
rtf.SelBold = True                                              <------  bolded here
rtf.Text = rtf.Text & " No Highlighted"                <------  reset here
End Sub


This works with the example you gave:

Private Sub Command1_Click()
    Dim iStart As Integer
    Dim iLen As Integer
   
    rtf.Text = "Text is "
    iStart = Len(rtf.Text)
    iLen = Len("Highlighted")                            <----- get len of text to be bolded
    rtf.Text = rtf.Text & "Highlighted"
    rtf.Text = rtf.Text & " No Highlighted"          <------ append other string
    rtf.SelStart = iStart
    'rtf.SelLength = Len(rtf.Text) - iStart
    rtf.SelLength = iLen                                    <------ set length this way
    rtf.SelBold = True                                       <------ bold last

End Sub

Hope this gets you in the right direction.
Preece
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1400 total points
ID: 16235737
As Preece pointed out, you are losing your formatting when you set the .Text() property:

    rtf.Text = rtf.Text & "...something..."         ' setting .Text() destroys formatting

If you want to append text to an RTB, then use code like this:

    rtf.SelStart = Len(rtf.Text)
    rtf.SelLength = 0
    rtf.SelText = "...the text to append to the RTB..."
0
 
LVL 12

Assisted Solution

by:Preece
Preece earned 600 total points
ID: 16235903
Ok, this is a better working example:

Private Sub Command1_Click()
    Dim iStart As Integer
    Dim iLen As Integer
   
    rtf.Text = "Text is "
    iStart = Len(rtf.Text)
    iLen = Len("Highlighted")
    rtf.Text = rtf.Text & "Highlighted"
    rtf.SelStart = iStart
    'rtf.SelLength = Len(rtf.Text) - iStart
    rtf.SelLength = iLen
    rtf.SelBold = True
    rtf.SelStart = Len(rtf.Text)
    rtf.SelLength = 0
    rtf.SelBold = False
    rtf.SelText = " No Highlighted"
   
   
End Sub

Preece
0
 
LVL 9

Author Comment

by:william007
ID: 16235946
Thanks:-)
0
 
LVL 9

Author Comment

by:william007
ID: 16239040
Hi, there is a continuous question here,
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21781161.html
which is about the problem encounter while appending text.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month20 days, 9 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question