|
-
Aug 4th, 2004, 01:08 PM
#1
Thread Starter
Lively Member
Syntax coloring
I wrote this little program for syntax coloring somthing (letters ect).
But It gives me the error "cannot convert Number to integer" With the first case. Can some one help?
VB Code:
Private Sub RichTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox.TextChanged
Dim source As String
Dim rtb As New RichTextBox ' name rtb as a RichText Box type
Dim Codearray() As String ' It's the array of text
Dim currentline As String ' The currentline of Text
Dim Line As Integer ' Dunno why I can't use somthing smaller ...
Dim I As Decimal 'Largestest thing
Codearray = Split(source, vbCrLf) ' split Code array from source at Center Left
For I = LBound(Codearray) To UBound(Codearray) 'From lower case to uppercase
currentline = Codearray(I) ' Code array for line
' add auto tab
Select Case Left() ' the left case
Case "\" ' comments
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Italic) ' make her bold!
rtb.ForeColor() = Drawing.Color.Gray 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "!" ' normal number
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Strikeout) ' make her bold!
rtb.ForeColor() = Drawing.Color.Purple 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "&" ' Literal
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.Green 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "%" ' Small number
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.DarkRed 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case ""
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold) ' make her bold!
rtb.ForeColor() = Drawing.Color.AntiqueWhite 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "(" ' comments
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Italic) ' make her bold!
rtb.ForeColor() = Drawing.Color.Bisque 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case ")" ' normal number
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Strikeout) ' make her bold!
rtb.ForeColor() = Drawing.Color.Bisque 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "{" ' Literal
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.Brown 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "}" ' Small number
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.Brown 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case ":"
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold) ' make her bold!
rtb.ForeColor() = Drawing.Color.Pink 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
If InStr(1, currentline, "(") > 0 Then
rtb.TabIndex = 1
Dim comment As Long
comment = InStr(InStr(1, currentline, ")"), currentline, "*")
rtb.SelectedRtf = rtb.SelectedRtf & Chr(10) & Chr(13)
End If
Case Else
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold) ' make her bold!
rtb.BackColor() = Drawing.Color.Red 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
End Select
Next
End Sub
-
Aug 4th, 2004, 06:27 PM
#2
PowerPoster
Hi,
I don't see how your Select case works at all!
" Select Case Left() ' the left case "
What is Left() ??
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 4th, 2004, 06:36 PM
#3
Thread Starter
Lively Member
I didn't compleatly program it. I was transeferring what I could from VB6. And that was in there. I don't even know the function, but last I remember, that wasn't giving me the error.
-
Aug 4th, 2004, 08:44 PM
#4
Fanatic Member
i don't know if this helps but i code like this but only c# comments are colorize. regex function and best for other event not the textchanged. in my case, button click
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim re As New Regex("(//.*[\n])|(///.*[\n])|(#region.*[\n])|(/\*.*?\*/)|(/\*[^""]*\*/)", RegexOptions.IgnoreCase)
Dim mc As MatchCollection = re.Matches(RichTextBox1.Text)
Dim ma As Match
For Each ma In mc
RichTextBox1.HideSelection = True
RichTextBox1.Select(ma.Index, ma.Length)
RichTextBox1.SelectionColor = Color.Green
RichTextBox1.SelectionStart = ma.Index + ma.Length
RichTextBox1.SelectionLength = 0
RichTextBox1.SelectionColor = Color.Black 'revert the color
Next
End Sub
if this doesn't help, sorry.
help from pirate and dynamic_sysop
-
Aug 5th, 2004, 07:28 AM
#5
PowerPoster
Originally posted by Word2
I didn't compleatly program it. I was transeferring what I could from VB6. And that was in there. I don't even know the function, but last I remember, that wasn't giving me the error.
Hi,
Before posting code you must check it out yourself to make sure of the problem you are posting.
Your select case cannot possibly work as posted. Left() has two possibilities in VB.NET. If used in a form it refers to the Left position. If used where a string is the only possibility involved, then it refers to the leftmost characters. Neither of these two circumstances apply to your posted code. It should not even compile, so please check it out yourself and then post your problem.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 5th, 2004, 09:11 AM
#6
Thread Starter
Lively Member
I have checked and replaced. But it now atleast lets me enter letters and such. Althought, it still will not color the string.
My new code compiles and runs with no runtime errors, but doesn't color the line.
VB Code:
Private Sub RichTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox.TextChanged
Dim source As String
Dim rtb As New RichTextBox ' name rtb as a RichText Box type
Dim Codearray() As String ' It's the array of text
Dim currentline As String ' The currentline of Text
Dim I As Decimal 'Largestest thing
Codearray = Split(source, vbCrLf) ' split Code array from source at Center Left
For I = LBound(Codearray) To UBound(Codearray) 'From lower case to uppercase
currentline = Codearray(I) ' Code array for line
Select Case currentline
Case "\" ' comments
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Italic) ' make her bold!
rtb.ForeColor() = Drawing.Color.Gray 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "!" ' normal number
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Strikeout) ' make her bold!
rtb.ForeColor() = Drawing.Color.Purple 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "&" ' Literal
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.Green 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "%" ' Small number
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.DarkRed 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case " "
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold) ' make her bold!
rtb.ForeColor() = Drawing.Color.AntiqueWhite 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "(" ' comments
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Italic) ' make her bold!
rtb.ForeColor() = Drawing.Color.Bisque 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case ")" ' normal number
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Strikeout) ' make her bold!
rtb.ForeColor() = Drawing.Color.Bisque 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "{" ' Literal
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.Brown 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case "}" ' Small number
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.Brown 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
Case ":"
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold) ' make her bold!
rtb.ForeColor() = Drawing.Color.Pink 'Change color
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
If InStr(1, currentline, "(") > 0 Then
rtb.TabIndex = 2
Dim comment As Long
comment = InStr(InStr(1, currentline, ")"), currentline, "*")
rtb.SelectedRtf = rtb.SelectedRtf & Chr(10) & Chr(13)
End If
Case Else
rtb.Text = currentline ' trb on current line
rtb.SelectedText = Len(currentline) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold) ' make her bold!
rtb.BackColor() = Drawing.Color.Red 'Change color
End Select
Next
End Sub
-
Aug 6th, 2004, 03:50 PM
#7
PowerPoster
Hi,
Looking at all your posts I still think your Select Case is wrong. Unless there is only one character in currentline I think it should be
VB Code:
Select Case Microsoft.VisualBasic.Left(currentline, 1)
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 8th, 2004, 01:36 PM
#8
Thread Starter
Lively Member
Unfortunatly that didn't change anything.
-
Aug 8th, 2004, 06:39 PM
#9
PowerPoster
Originally posted by Word2
Unfortunatly that didn't change anything.
Right.
I have copied your code in full. There are a lot of errors. assuming you have Option Strict On, each of your
rtb.SelectedText = Len(currentline)
should be
rtb.SelectedText = CStr(Len(currentline))
Also, the string Source never gets filled and I would guess that your code
rtb.SelectedRtf = rtb.Text = Chr(10) & Chr(13)
should be
rtb.SelectedRtf = rtb.Text & Chr(10) & Chr(13)
ALSO, you cannot declare I as Decimal and then use it as an integer in the array.
I cannot see how you have made the rtb visible, so have you put one on the form from the toolbox as well as having created an instance in code?
I do not see how your posted code could possibly have compiled.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 8th, 2004, 07:57 PM
#10
PowerPoster
And you need to start learning about debugging procedures. A breakpoint inserted at the beginning of that code (when you do manage to compile it) wil give you a big clue as to where the problem lies - ie is it the Select Case not matching the conditions, or is it the code within the Case startements not doing what you expect.
-
Aug 8th, 2004, 08:38 PM
#11
Thread Starter
Lively Member
Ok, fixed everything you said, and then some :P.
I get this error apon running it.
Invalid file format.
VB Code:
Private Sub RichTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox.TextChanged
RichTextBox.Visible = True
Dim source As String
Dim rtb As New RichTextBox ' name rtb as a RichText Box type
rtb.Visible = True
Dim Codearray() As String ' It's the array of text
Dim currentline As String ' The currentline of Text
Dim I As Long 'Largestest thing
Codearray = Split(source, vbCrLf) ' split Code array from source at Center Left
For I = LBound(Codearray) To UBound(Codearray) 'From lower case to uppercase
currentline = Codearray(CInt(I)) ' Code array for line
Select Case currentline
Case "\" ' comments
rtb.Text = currentline ' trb on current line
rtb.SelectedRtf = CStr(Len(currentline)) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Italic) ' make her bold!
rtb.ForeColor() = Drawing.Color.Gray 'Change color
rtb.SelectedRtf = rtb.Text & Chr(10) & Chr(13)
Case "!" ' normal number
rtb.Text = currentline ' trb on current line
rtb.SelectedRtf = CStr(Len(currentline)) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Strikeout) ' make her bold!
rtb.ForeColor() = Drawing.Color.Purple 'Change color
rtb.SelectedRtf = rtb.Text & Chr(10) & Chr(13)
Case "&" ' Literal
rtb.Text = currentline ' trb on current line
rtb.SelectedRtf = CStr(Len(currentline)) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.Green 'Change color
rtb.SelectedRtf = rtb.Text & Chr(10) & Chr(13)
Case "%" ' Small number
rtb.Text = currentline ' trb on current line
rtb.SelectedRtf = CStr(Len(currentline)) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.DarkRed 'Change color
rtb.SelectedRtf = rtb.Text & Chr(10) & Chr(13)
Case ")" ' normal number
rtb.Text = currentline ' trb on current line
rtb.SelectedRtf = CStr(Len(currentline)) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Strikeout) ' make her bold!
rtb.ForeColor() = Drawing.Color.Bisque 'Change color
rtb.SelectedRtf = rtb.Text & Chr(10) & Chr(13)
Case "{" ' Literal
rtb.Text = currentline ' trb on current line
rtb.SelectedRtf = CStr(Len(currentline)) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.Brown 'Change color
rtb.SelectedRtf = rtb.Text & Chr(10) & Chr(13)
Case "}" ' Small number
rtb.Text = currentline ' trb on current line
rtb.SelectedRtf = CStr(Len(currentline)) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Regular) ' make her bold!
rtb.ForeColor() = Drawing.Color.Brown 'Change color
rtb.SelectedRtf = rtb.Text & Chr(10) & Chr(13)
Case ":"
rtb.Text = currentline ' trb on current line
rtb.SelectedRtf = CStr(Len(currentline)) ' select text
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold) ' make her bold!
rtb.ForeColor() = Drawing.Color.Pink 'Change color
rtb.SelectedRtf = rtb.Text & Chr(10) & Chr(13)
If InStr(1, currentline, "(") > 0 Then
rtb.TabIndex = 2
Dim comment As Long
comment = InStr(InStr(1, currentline, ")"), currentline, "*")
rtb.SelectedRtf = rtb.SelectedRtf & Chr(10) & Chr(13)
End If
Case Else
rtb.Text = currentline ' trb on current line
rtb.SelectedRtf = CStr(Len(currentline)) ' select text ' ' ' 'Error is here' ' '
rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold) ' make her bold!
rtb.ForeColor() = Drawing.Color.Brown 'Change color
End Select
Next I
CCE.ActiveForm.Text = rtb.Text
CCE.ActiveForm.Refresh()
End Sub
I get it in the "rtb.SelectedRtf = CStr(Len(currentline))"
Line.
-
Aug 8th, 2004, 08:41 PM
#12
Thread Starter
Lively Member
Originally posted by SuperSparks
And you need to start learning about debugging procedures. A breakpoint inserted at the beginning of that code (when you do manage to compile it) wil give you a big clue as to where the problem lies - ie is it the Select Case not matching the conditions, or is it the code within the Case startements not doing what you expect.
I changed it. Now it freezes on the Case Else.
Break points. Will look into.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|