
Originally Posted by
Pingo
The pos value is returning -1 which throws that error.
Perhaps add a check to see if the value is -1.
Code:
If pos <> -1 Then
RichTextBox1.Select(pos, oneWord.Length)
RichTextBox1.SelectionColor = Color.Blue
End If
Something small i noticed in your code.
You're increasing you pos by one
pos += 1
Shouldn't you be changing the value to the last known position so you won't need to scan one by one.
I might of read the code incorrectly so i might be wrong.
I Think One is Better !!
But I'll Try ur Advice !!
and ALSO If The Code u Gave me !
What Should I Put in The Else ?!
---------- Post added at 10:24 PM ---------- Previous post was at 09:42 PM ----------
I Fixed It xD
But Nw I Need a Code That adds a Character at the end of every line in RichTextBox.Text To Start Finalizing My Project ![COLOR="Silver"]
---------- Post added at 11:02 PM ---------- Previous post was at 10:44 PM ----------
FaCinG Another Problem !!
This is The Final Code :
Code:
Dim rx As New Regex("AddHandler |AddressOf |Alias |And |AndAlso |Ansi |As |Assembly |Auto |Boolean |ByRef |Byte|" + _
"ByVal |Call |Case |Catch |CBool |CByte |CChar |CDate |CDec |CDbl |Char |CInt |Class |CLng |CObj |Const |CShort |CSng |" + _
"CStr |CType |Date |Decimal |Declare |Default |Delegate |Dim |DirectCast |Do |Double |Each |Else |ElseIf |End |Enum |" + _
"Erase |Error |Event |Exit |False|Finally |For |Friend |Function |Get |GetType |GoSub |GoTo |Handles |If |Implements |Imports |" + _
"In |Inherits |Integer |Interface |Is |Let |Lib |Like |Long |Loop |Me |Mod |Module |MustInherit |MustOverride |MyBase |" + _
"MyClass |Namespace |New |Next|Not |Nothing |NotInheritable |NotOverridable |Object |On |Option |Optional |Or |OrElse |" + _
"Overloads |Overridable |Overrides |ParamArray |Preserve |Private |Property |Protected |Public |RaiseEvent |ReadOnly |ReDim |" + _
"REM |RemoveHandler |Resume |Return |Select |Set |Shadows |Shared |Short |Single |Static |Step |Stop |String |Structure |Sub |" + _
"SyncLock |Then |Throw |To |True |Try |TypeOf |Unicode |Until |Variant |When |While |With |WithEvents |WriteOnly |Xor |#Const |#ExternalSource |#If...Then...#Else |#Region |")
RichTextBox1.Select(0, RichTextBox1.Text.Length)
RichTextBox1.SelectionColor = Color.Black
For Each m As Match In rx.Matches(RichTextBox1.Text)
RichTextBox1.SelectionStart = m.Index
RichTextBox1.SelectionLength = m.Value.Length
RichTextBox1.SelectionColor = Color.Blue
Next
rx = New Regex(""".+""")
For Each m As Match In rx.Matches(RichTextBox1.Text)
RichTextBox1.SelectionStart = m.Index
RichTextBox1.SelectionLength = m.Value.Length
RichTextBox1.SelectionColor = Color.Maroon
Next
This Bold Line is The Problem !!
I have it in my code for not to let all Text Change to Blue !!
But The Problem is When I Start Typing in a LONG CODE !!
it Goes Till The ZERO and Start Highlighting All again !!
So How to Make it start From The Place I'm Typing in