I was wondering if there was a way to make it so that anything following certain criteria would colour it a certain way for instance making any text within brackets green or the word following '/' red. I'm just starting out with VB so forgive me if this is a noobish question :P
Yes, you can do that - that's the basic purpose of RTB: formatting text.
Here is a small routine that underlines selected text. You can modify it as you wish:
VB Code:
Public Sub UnderlineText(objRTB As Object, strFind As String)
Hi guys, thanks for the responses but thats not quite what I was looking for. I was thinking that it would be for instance /text and (text) and it would occur with any text not just preprogrammed words or ones that need users to enter anything.
What would the colors be based on? If you can provide instances that work in all conditions, then you can program it in. If you have a / up to a ), then you could colorize the first and last word.
The colours would be set by a variable I guess I'd like them to be customizable and it'd just be one word within so coloring the first and last word wouldn't be necasary as they'd be one and the same.
I'm still not entirely sure what you mean, the beginning would be the symbol / then next would be any word that the user chooses to put in and it would be a color I define in a variable and then a space and then the following text would be black again or something to that effect.
Example: Hello I am Solg, how /are you?
Last edited by Solg; Nov 26th, 2005 at 12:32 AM.
Reason: Forgot Example
So, you want to start at the first "/" and then change the color of everything up to the first space? That could cause problems, but it could be done. If you add a closing tag, it would be more generic.
That would be much better. Use the .Find method, which will return the location of a string in a rtb. Change the "\" to "", and then Set .SelStart to the position. Then do the same for the "\". Then use .SelStart to the original location, and .SelLength to the difference between "\" and "/".
This will highlight the word you want colored. Once it's highlighted, you can use .SelColor to change it.
My code ran fine for me. I just tested it again. It selects the whole line in the rtb when you click on a line, and the replace works on all instances of a phrase.
Okay I'm sorry to keep doing this and I thank you guys for being so helpful but I've been messing with this for a couple days or so and I can't seem to get it to work right. Its for a script editor for a game I play if anyone is wondering I want it to change it as its being typed out not just when a button is hit and thats where I run into problems.
Example for script when done again if anyone is wondering:
"When someone moves over here"
"Set variable /variablename\ to 3"
Also should be red for /v, /va, /var etc. etc. though Its giving me LOADS of headaches all help is appreciated
This actually works for the colouring part but when I press space to continue on with the text it gives me an error I go into debugging and it says that lngLength is actually the negative of whatever it should be. So I tried multiplying it by -1 but that didn't work, any suggestions?