ChrisMoje

Hi guys,
May I know if somebody here knows how to create a "videoke-like" effect on each word in a textbox or rtf This is how it should work....a timer would trigger each event. each word will be formatted in bold (say for every 2 seconds) and a different color say..blue, and then jump to the next group of words until it sees the end of the paragraph....Thanks



Re: Visual Basic Express Edition Videoke like effect

Jonathan Allen

It's possible using a rich textbox. You need to learn three things...

1. How to "tokenize" a string into words.

2. How to change colors and fonts in a rich textbox.

3. How to use a Timer.

What do you want to learn first





Re: Visual Basic Express Edition Videoke like effect

ChrisMoje

Hi Jonathan,

Thanks, first i want to learn how to tokenize strings, does this means it will search for a space in between and treat it as a word

I understand I would write the codes inside the timer event. Thanks





Re: Visual Basic Express Edition Videoke like effect

Jonathan Allen

Here is one way to do it. It is written to be used in a Console project. I don't know where you are in your training, so feel free to ask questions.

Module Module1

Sub Main()

Dim mySentence As String = "The cat in the hat is black."

Dim XXXXXXXXXX As String = " 111111111122222222"

Dim YYYYYYYYYY As String = "0123456789012345678901234567"

'The second/third line is just to show how the letters are numbered in the string from 0 to 27.

Dim startIndex As Integer = 0 'assume the first word starts at letter 0

Dim endIndex As Integer

Do

endIndex = FindWordEnd(mySentence, startIndex) 'get the end of the current word

'write the current word to the screen

Console.WriteLine(mySentence.Substring(startIndex, (endIndex - startIndex + 1))) 'note that SubString needs the length, not the ending index

'get the start of the next word

startIndex = FindWordStart(mySentence, endIndex)

Loop Until startIndex = -1 '-1 means there are no more words

Console.ReadKey()

End Sub

Function FindWordStart(ByVal source As String, ByVal lastEnd As Integer) As Integer

'First make sure we are not at the end of the string

If lastEnd >= source.Length Then Return -1 'no more words

'Create a index variable

Dim index As Integer = lastEnd + 1

'Skip all the spaces and tabs before the word

'Note that we are also making sure we didn't go past the end of the string

Do While index < source.Length AndAlso Char.IsWhiteSpace(source, index)

index += 1 'goto next letter

Loop

'Have we run out of letters

If index >= source.Length Then Return -1

'We must have found the start of a word

Return index

End Function

Function FindWordEnd(ByVal source As String, ByVal lastStart As Integer) As Integer

'First make sure we are not at the end of the string

If lastStart >= source.Length Then Return -1 'no more words

'Create a index variable

Dim index As Integer = lastStart

'Skip all the characters that are NOT spaces or tabs

'Note that we are also making sure we didn't go past the end of the string

Do While index < source.Length AndAlso Not Char.IsWhiteSpace(source, index)

index += 1 'goto next letter

Loop

'Have we run out of letters

If index >= source.Length Then Return (source.Length - 1) 'the last letter in the string

'We must have found the end of a word

Return index - 1 'the last letter before we found a space

End Function

End Module





Re: Visual Basic Express Edition Videoke like effect

ChrisMoje

Hi Jonathan,

I run the program using control application,but I cannot see the connection to my project. I have to open a file, display it in my rtf control. Then when i press the button it will highlight each word, with lest say blue color. When I run this application, each word has been lined up vertically, just like putting vbcrlf every after word. Thanks






Re: Visual Basic Express Edition Videoke like effect

Jonathan Allen

This is just to show you how to seperate out the words. Later, you will use the startIndex and endIndex to highlight the words in the rtf box. For example...

Dim startIndex As Integer = 5

Dim endIndex As Integer = 5

Dim length As Integer = (endIndex - startIndex + 1)

RichTextBox1.Select(startIndex, length)

RichTextBox1.SelectionColor = Color.Blue

RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Bold)





Re: Visual Basic Express Edition Videoke like effect

ChrisMoje

Hi Jonathan,

Thanks for the help, I'll try this example and inform you on my progress. :-)






Re: Visual Basic Express Edition Videoke like effect

Jonathan Allen

Good luck.