-
[RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HELP NEEDED]
Hi all...
I am trying to create a small vb6 code viewer.Which will simply display the VB6 codes in color coded form. See below for an example:
vb Code:
Option Explicit
Private Sub Command1_Click() '~~~ Search button
Dim i As Long
List2.Clear '~~~> Empty everything
For i = 0 To List1.ListCount - 1 '~~~> Loop through the list in 1st Listbox
If InStr(1, List1.List(i), Trim$(Text1.Text), vbTextCompare) <> 0 Then '~~> Checking for the entry
List2.AddItem List1.List(i) '~~~> If found, add it to the 2nd Listbox
End If
Next i
End Sub
Private Sub Form_Load()
'~~~ Load the listbox with sample data
List1.AddItem "D:\MUSIC\Music Collection Updated\Akon ft nas - locked up rmx.mp3"
List1.AddItem "D:\MUSIC\Music Collection Updated\Ciara - Oh.mp3"
List1.AddItem "C:\MUSIC\Music Collection Updated\Fabolous - Can U hear me.mp3"
List1.AddItem "C:\MUSIC\Music Collection Updated\Fabolous - Cant_let_you_go.mp3"
End Sub
Here, the reserved words are set with the blue color, comments with green, constants(numbers) with pink and text with brown.
How can I implement the same coloring methods in my own VB6 code viewer..????
Any ideas...???
Thanks.... :wave:
Edit:
I know the basic methods for finding and changing words by using Find method of RichTextBox and some basic manipulations using InStr(), Mid(), Replace(), etc...
But I was looking for something that is more efficient and speedy, because the code might be of large lines....
For displaying the VBCode, I will be using a RichtTextbox...
Thanks... :wave:
-
Re: Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HELP NEEDED]
-
Re: Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HELP NEEDED]
Quote:
Originally Posted by
akhileshbc
I am trying to create a small vb6 code viewer.Which will simply display the VB6 codes in color coded form.
Well what I use to display VB code on A1vbcode is Mark's Syntax.zip. It displays the code in a web browser then you just copy and paste it into you reply. Its a pity we don't use a similar code on here. The VB Code used to be good but you can only copy one line at a time. I know some uses and made a vb app to copy and paste the code but you should have to its only text. I don't know if thats what you mean? ;)
-
Re: Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HELP NEEDED]
Quote:
Originally Posted by
Keithuk
Well what I use to display VB code on
A1vbcode is
Mark's Syntax.zip. It displays the code in a web browser then you just copy and paste it into you reply. Its a pity we don't use a similar code on here. The VB Code used to be good but you can only copy one line at a time. I know some uses and made a vb app to copy and paste the code but you should have to its only text. I don't know if thats what you mean? ;)
Thanks Keith... :wave:
Yeah, exactly... That's what I want to achieve.... :)
Quote:
Originally Posted by
Hack
Thanks Hack.... :wave:
rep+ both of you... :)
-
Re: Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HELP NEEDED]
As my friend Keith stated, Marks 'Syntax Highlighter' does a really nice job. I would use it here on VBF if I could. There are also a few similar apps on PSC.
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
akhileshbc
I am trying to create a small vb6 code viewer.Which will simply display the VB6 codes in color coded form. See below for an example:
Akhil
You seem to have some good replies already.
About all I'd be good for would be to suggest a brute-force approach,
well, at least for reserved words -- you'd need a list of them, and if found,
set color to blue. Comments could just be handled by looking for
apostrophe. And so on...
Do you want to go that route, or are you satisfied with other guys' replies?
Spoo
-
Re: Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HELP NEEDED]
Quote:
Originally Posted by
CDRIVE
As my friend Keith stated, Marks 'Syntax Highlighter' does a really nice job. I would use it here on VBF if I could. There are also a few similar apps on PSC.
Thanks CDRIVE.... :wave:
I tried that one, but it is giving some errors on runtime..!
Quote:
Key is already assigned with an element to this collection
I think it is due to some duplicate entries in keywords.txt file. (like cbool, cbyte, etc having two copies of each).... :)
But the EXE file attached to it, is working perfect... :)
I will play with codes and will post here if I am stuck at any part... :wave:
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Ah!!!!
I have tried the code before... in fact I have it in my laptop... I have implemented the same in the Code Generator... See the link in my signature ;)
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
Spoo
Akhil
You seem to have some good replies already.
About all I'd be good for would be to suggest a brute-force approach,
well, at least for reserved words -- you'd need a list of them, and if found,
set color to blue. Comments could just be handled by looking for
apostrophe. And so on...
Do you want to go that route, or are you satisfied with other guys' replies?
Spoo
Thanks spoo.... :wave:
Could you show a small sample or an example for describing the 'brute-force approach' (it's a new term for me :o)... :wave:
Edit: I found it after Googling. Thanks... :wave:
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
koolsid
Ah!!!!
I have tried the code before... in fact I have it in my laptop... I have implemented the same in the Code Generator... See the link in my signature ;)
Wow that's a nice one... :wave:
Do you have the source code...???? I mean, do you mind sharing it with us... :wave:
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Sure pm me your email address... In the mean time I'll search my laptop for the same... Also go through the attachment and see the help file. The .Hlp file has pictures so you can see how the codes automatically gets formatted (colored) in the RTB :)
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
koolsid
Sure pm me your email address... In the mean time I'll search my laptop for the same... Also go through the attachment and see the help file. The .Hlp file has pictures so you can see how the codes automatically gets formatted (colored) in the RTB :)
Done.... :thumb:
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Akhil
"Brute-force" -- as in not terribly elegant or efficient, but gets the job done
Anyway, before posting code, let me see if I understand your situation.
I'm assuming that you would..
1. Open a .FRM file as a text file
2. Skip over the control definitions and get to declarations and then subs and functions
3. Load your RTB with 20 or so lines of code
4. Have a text file that contains reserved words, say RW.txt
5. Look up each word in the RTB in RW.txt -- if found, set color to blue
6. If find apostrophe, set rest of line to green (comment).
7. and so on...
Is that what you are thinking of doing?
EDIT: I'm too late, I guess .. looks like you and Kool are on to something better.
Spoo
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Spoo you are on the right track but instead of using the Text File I have declared the words in a string for example
Code:
VB6ReservedWords = "Or|Do|And|Random|Append|Binary|Exit|Then|GoTo|Case|Select|End|ReDim|" _
& "For|Each|Loop|While|Until|Next|True|False|Sub|Function|As|Private|Dim|Open|Access|" _
& "Else|ElseIf|Public|Close|Open|If|ByVal|(ByVal|Set|Nothing|Option|Explicit|Declare|" _
& "Long|Long,|Long)|Lib|LBound|UBound|With|Call|Integer|Integer,|Integer)|Read|Lock|" _
& "Byte|Byte)|Byte,|Double|Double)|Double,|Boolean|Boolean)|Boolean,|Any|Any,|Any)|" _
& "Currency|Currency,|Currency)|Date|Date,|Date)|New|New,|New)|Object|Object,|Object)|" _
& "Single|Single,|Single)|String|String,|String)|Variant|Variant,|Variant)|Alias|Const|" _
& "Public|Not|Enum|Static|Friend|ByRef|(ByRef|ParamArray|Type|WithEvents|Resume|Is|Set|" _
& "Debug.Assert|Debug.Print|False:|Else:|Global|EndIf"
MyArray = Split(VB6ReservedWords, "|")
I am also using the LockWindowUpdate API to ensure that the RTB doesn't flicker when the words get colored... If you see the help file in the attachment in that link, you will see the snapshots on how it looks...
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
Spoo
Akhil
"Brute-force" -- as in not terribly elegant or efficient, but gets the job done
Anyway, before posting code, let me see if I understand your situation.
I'm assuming that you would..
1. Open a .FRM file as a text file
2. Skip over the control definitions and get to declarations and then subs and functions
3. Load your RTB with 20 or so lines of code
4. Have a text file that contains reserved words, say RW.txt
5. Look up each word in the RTB in RW.txt -- if found, set color to blue
6. If find apostrophe, set rest of line to green (comment).
7. and so on...
Is that what you are thinking of doing?
EDIT: I'm too late, I guess .. looks like you and Kool are on to something better.
Spoo
Yeah... But some changes... I thought about creating a program that can open the project files(frm and mod) and parse the code blocks (or the pasted codeblocks - in a Richtextbox) to be formatted for displaying it in this forum. The vbCode tags in this forum has a disadvantage that, it will display line numbers on the codes, which makes it difficult for the end user to copy the CODE. So, if the code is formatted in such a way that, it will color it just like the vbCodes but wrapped inside the CODE tags, it will certainly be a help for both the users. I was trying to create such a program.... :)
Thanks... :wave:
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Kool
Cool list of reserved words
Akhil
Nice project. And I get your point about line numbers when using VBCode wrapper.
I see you've marked this as RESOLVED, so I'll stand down.
Spoo
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
Spoo
Akhil
Nice project. And I get your point about line numbers when using VBCode wrapper.
I see you've marked this as RESOLVED, so I'll stand down.
Spoo
Thanks to you and all those who had helped me... Thanks guys.... :wave:
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
So if this topic is Resolved which method have you used? ;)
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
Keithuk
So if this topic is Resolved which method have you used? ;)
I am trying out the 3 methods... Hack's one, Keith's and Koolsid's (from his addin). I am playing with these three methods and trying to understand the techniques used ;)
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
koolsid
Spoo you are on the right track but instead of using the Text File I have declared the words in a string for example
Code:
VB6ReservedWords = "Or|Do|And|Random|Append|Binary|Exit|Then|GoTo|Case|Select|End|ReDim|" _
& "For|Each|Loop|While|Until|Next|True|False|Sub|Function|As|Private|Dim|Open|Access|" _
& "Else|ElseIf|Public|Close|Open|If|ByVal|(ByVal|Set|Nothing|Option|Explicit|Declare|" _
& "Long|Long,|Long)|Lib|LBound|UBound|With|Call|Integer|Integer,|Integer)|Read|Lock|" _
& "Byte|Byte)|Byte,|Double|Double)|Double,|Boolean|Boolean)|Boolean,|Any|Any,|Any)|" _
& "Currency|Currency,|Currency)|Date|Date,|Date)|New|New,|New)|Object|Object,|Object)|" _
& "Single|Single,|Single)|String|String,|String)|Variant|Variant,|Variant)|Alias|Const|" _
& "Public|Not|Enum|Static|Friend|ByRef|(ByRef|ParamArray|Type|WithEvents|Resume|Is|Set|" _
& "Debug.Assert|Debug.Print|False:|Else:|Global|EndIf"
MyArray = Split(VB6ReservedWords, "|")
I am also using the LockWindowUpdate API to ensure that the RTB doesn't flicker when the words get colored... If you see the help file in the attachment in that link, you will see the snapshots on how it looks...
I put all of my keywords in an access database. That makes it easy to add/remove/whatever.
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Many ways to skin a cat (Forgive me P.E.T.A), Hack :)
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
Keithuk
Its a pity we don't use a similar code on here. The VB Code used to be good but you can only copy one line at a time. I know some uses and made a vb app to copy and paste the code but you should have to its only text.
Quote:
Originally Posted by
akhileshbc
The vbCode tags in this forum has a disadvantage that, it will display line numbers on the codes, which makes it difficult for the end user to copy the CODE.
You guys should know that the VB Code tags here on vbforums were fixed last year. Copying code that has line numbers is no longer a problem; just copy & paste as normal and it works without a hitch. Code copies properly, line numbers are ignored, and no 3rd party helper application is required.
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
Ellis Dee
You guys should know that the VB Code tags here on vbforums were fixed last year. Copying code that has line numbers is no longer a problem; just copy & paste as normal and it works without a hitch. Code copies properly, line numbers are ignored, and no 3rd party helper application is required.
Thanks Ellis.... :wave:
But I think it is not yet fixed....! I just tried the code in the first post and it's the same as in the previous days (includes the numbers) :wave:
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
I had posted the project in our CodeBank... : http://www.vbforums.com/showthread.php?t=608000 ...:wave:
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
akhileshbc
Thanks Ellis.... :wave:
But I think it is not yet fixed....! I just tried the code in the first post and it's the same as in the previous days (includes the numbers) :wave:
Works fine for me, but I use Internet Explorer. It's probably your browser.
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
Quote:
Originally Posted by
Ellis Dee
Works fine for me, but I use Internet Explorer. It's probably your browser.
For me it's Firefox 3 ...:)
Edit:
Yeah, I tried copying codes using IE8 and it's working fine... :wave: Only Firefox is having the problem.... :)
-
Re: [RESOLVED] Parsing and coloring the VB CODES in my Richtextbox [SUGGESTIONS & HEL
That's the danger of using the "little guy" browser.