Hey all I am making a little SQL query textarea in my app. I am stylizing the text based on keywords found and I am not to a point where I want to make strings (any characters in single quotes, including the single quotes) be red.
Below is the code I am using (I realize it isnt the most optimized way to do this but I dont need it to stylize as Im typing) for turning keywords blue.
I am open to making this whole thing cleaner and run quicker as well so really any help with that and getting the strings to be red would be much appreciated.
Main.QueryEditor1.QueryArea.Visible = False
Var ms As Integer = Main.QueryEditor1.QueryArea.SelectionStart
Var ml As Integer = Main.QueryEditor1.QueryArea.SelectionLength
Main.QueryEditor1.QueryArea.SelectionStart = 0
Main.QueryEditor1.QueryArea.SelectionLength = Main.QueryEditor1.QueryArea.Text.Length
Main.QueryEditor1.QueryArea.SelectionTextColor = Color.Black
Var s As String = Main.QueryEditor1.QueryArea.Text
Var l As Integer = s.Length-1
Var index2 As Integer
Var bluewords() As String = Array("SELECT","FROM","WHERE","CASE","AS ","WITH(nolock)","ON ","THEN","ELSE","DISTINCT","WHEN","CHAR","END","VARCHAR","WHERE","ORDER BY","GROUP BY")
Var graywords() As String = Array("OR ","IS ","NULL","=",">","<","+","-","AND","LIKE","NOT LIKE","IN ","NOT IN ","BETWEEN","INNER JOIN")
Var pinkwords() As String = Array("CAST","CONVERT","CHARINDEX","SUBSTRING","ISNULL")
For index1 As Integer = 0 To l
For each pw as String in pinkwords
index2 = s.IndexOf(index1, pw)
If index2 = index1 Then
Main.QueryEditor1.QueryArea.SelectionStart = index1
Main.QueryEditor1.QueryArea.SelectionLength = pw.Length
Main.QueryEditor1.QueryArea.SelectionTextColor = Color.Magenta
End If
Next
For each gw as String in graywords
index2 = s.IndexOf(index1, gw)
If index2 = index1 Then
Main.QueryEditor1.QueryArea.SelectionStart = index1
Main.QueryEditor1.QueryArea.SelectionLength = gw.Length
Main.QueryEditor1.QueryArea.SelectionTextColor = Color.Gray
End If
Next
For each bw as String in bluewords
index2 = s.IndexOf(index1, bw)
If index2 = index1 Then
Main.QueryEditor1.QueryArea.SelectionStart = index1
Main.QueryEditor1.QueryArea.SelectionLength = bw.Length
Main.QueryEditor1.QueryArea.SelectionTextColor = Color.Blue
End If
Next
Next
Main.QueryEditor1.QueryArea.Visible = TRUE
'Me.SetFocus
Main.QueryEditor1.QueryArea.SelectionStart = ms
Main.QueryEditor1.QueryArea.SelectionLength = ml
6 posts - 5 participants