-
I know this has been asked before but..
I have a rtf box that contains an article I want to make every instance of a particular work Ucase and Bold. I have the Ucase taken care but can't get the bold part to work. For the Ucase I changed to word to Ucase then used the replace function to replace every instance of it, I want to make it ucase and bold before I replace it. Any ideas?
Thanks in advance!
Cady
-
you use the rtfBox.SelBold = True
this sets or returns the bold value of the seltext area.
Hint:
if you have a lost of searching to do to make a specific word bold do your searching by dumping the rtfBox.text to string and using the instr() function. looping the rtfbox.find() is PAINFULL.
Been there, been burned :)
-
Paul282, this is what i did to make the word ucase.
strKW = election
myWord = StrConv(strKW, vbUpperCase)
RichTextBox.Text = Replace(RichTextBox.Text, strKW, myWord, 1, , vbTextCompare)
this worked great for making election to ELECTION but before replacing election for ELECTION I wanted to make it bold too.
I thought that I could use myWord.bold = true
or myWord.font.bold = true
but these didn't work
if I use richtextbox.SelBold=True
nothing happens.
What am I doing wrong???? And sorry if I am being dense, but it's Friday you know (any excuse!)
Cady
-
what about
richtextbox.seltext = ucase(richtextbox.seltext)
?
-
Try something like this (it's kind of slow so you may want to change it, but it should give you an idea)
NOTE: this is a VB 5.0 Pro example, unfortunatel I don't have VB 6 :(
Code:
Private Sub Command1_Click()
Dim I As Integer
With RichTextBox1
For I = 1 To Len(.Text) '//goes through each letter in rtf
If InStr(I, UCase(.Text), "CLOSE") > 0 Then '//if string has been found
.SelStart = InStr(I, UCase(.Text), "CLOSE") - 1 '//sets selstart
.SelLength = Len("Close") '//sets sellength
.SelBold = True '//makes selected text bold
.SelText = UCase(.SelText) '//makes selected text UCase
End If
Next I
End With
End Sub
Private Sub Form_Load()
'//I used file frunlog in my example, I'm not sure if you have it (you should though)
RichTextBox1.LoadFile "C:\frunlog.txt"
End Sub
HTH
[Edited by QWERTY on 04-21-2000 at 01:46 PM]
-
Performance on this is ok, even better if you set rtfbox.visible to false at the beginning and true again at the end...
Code:
Private Sub Command1_Click()
RTFBox.Text = "This is some text that I want the word 'the' changed to a bold 'the'"
Dim MyStr As String
Dim Start As Long
Dim BoldStr As String
Dim FoundPos As Long
BoldStr = "the"
Start = 1
FoundPos = 1
MyStr = RTFBox.Text 'not necessary here but in a big search you'd need this
Do While FoundPos > 0
FoundPos = InStr(Start, MyStr, BoldStr, vbTextCompare)
If FoundPos = 0 Then
Exit Sub
Else
With RTFBox
.SelStart = FoundPos - 1 ' instr() is 1 based but RTFbox is 0 based
.SelLength = Len(BoldStr)
.SelBold = True
End With
Start = FoundPos + 1
End If
Loop
End Sub