09-03-2000, 09:12 PM
I am writing an application designed for editing game data for a certain game. I want the code area (Rich Text Box) to be just like the Visual Basic code view. So that when you press 'enter' at the end of each line, the app will turn keywords blue, errors red, and comments green. How is this possible? Any suggestions or help would be appriciated!
09-03-2000, 09:17 PM
I would write the code to do this in the
select case keycode
09-04-2000, 12:03 AM
OK. I always try to not sound like the newbie that I am! But now that I've applied that code, my RTF just acts normal. Do you know how I could apply the code to read what I've typed and change the colors according to what I've typed? Thanks. :)
09-04-2000, 12:35 PM
You could have an array that contains all the keywords
In KeyUp you could use the
Instr(RichText1, word, vbTextCompare) function
For i=0 to uBound(aWords)
i=instr(RichText1, aWords(i), vbTextCompare)
if i>0 then
I hope this works
09-04-2000, 06:14 PM
Oh man! By the end of today, everyone will know my as the "total newbie" Anyway! I played around with your code amram, and the very first line it doesn't like. you wrote:
<font color=red>Instr(RichText1, word, vbTextCompare) function</font color=red>
I thought maybe it had something to do with that "function" word in the end, but that wasn't it. It's supposed to be:
<font color=blue>Instr</font color=blue>(RichText1, word, vbTextCompare) <font color=blue>= something...</font color=blue>
I wonder what? And there are many errors in the code itself too (that VB locates itself). I appriciate your help. And this project could be good if it works! I wish It would! Maybe amram or someone who can read his code can help me. Thanks!
09-04-2000, 06:30 PM
it does do that. That function word was telling you that InStr(was a function)
Copy Down the code that starts with Dim i% and ends with Next i
09-04-2000, 07:20 PM
Oh! OK! Silly me! But for some reason, it still has a problem with this line:
<font color=red>For i = 0 To UBound(aWords)</font color=red>
It says: "Type mismatch" when I press a letter in the box.
Also, if you're still here, do you know where I am supposed to actually define the words that should be in blue? Or do I do them one at a time... thanks!
09-05-2000, 07:06 PM
For the first problem. In the decalarations of a form, enter Dim aWords('Total # of words') as String
Then create a sub that adds all the words to the aray.
You can create a textfile containing every word and open the file and read it. If you need help with that, ask me.
So... If you have 80 keywords, you would do
Dim awords(80) as String
Seems to me like your making an editor of somekind
09-05-2000, 11:57 PM
Pretty smart guy amram! You must be a visual basic EXPERT!! You've been very helpful. :-) I didn't want to bother you anymore with my stupid newbie questions, so I tried the text file thing myself. I got it to open and read the text file, but it just genorates random keywords! I don't think that is right!
It's such a small detail, that makes such a good program! Thanks!
09-07-2000, 05:53 PM
Download the attachment. It shows you a pretty basic way to do it.
Not the best, but good enough
09-07-2000, 07:41 PM
Well, it does turn the words blue most of the time, but the problem is, they don't change black again! I'll try and work that problem out. If you know what the problem is without too much work, you can post it, that would be a great help. Thanks!
09-08-2000, 06:42 PM
09-08-2000, 07:54 PM
I think I know your problem. In My example, I used 21 keywords. Therefore, in the Declarations, I entered:
So Go to the Declarations and fix the code and enter
Dim asWords(107) as String
09-08-2000, 08:16 PM
Sorry, amram! I worded my question totally wrong. I did know about that array thing. But now I've made up my mind. With 108 keywords, you push a key, and it takes up to five seconds to generate the character!! Is it possible to program all the keywords right into VB without the use of an external text file. Then it would be quicker. People are counting on my program to be very good. And, without the external, people can't hack as easy! Thanks
09-08-2000, 08:23 PM
When the form loads, the array is populated. From there on, the text file should never be heard of again. U could always add it manually, but the code would be huge. Or, you could create a non-visible listbox, and add items into it. Then use the listbox instead of an array. However, an array is a lot more better.
09-09-2000, 12:54 AM
Well, as a personal preference, I like to have super-huge codes, because I KNOW it will work! And those 108 keywords did slow it down allot! I was wondering if you could take the time to show me how to do one keyword, and how to begin the next, and finally, how to use it when it's finished. From there, I can duplicate them, and make all 108. It takes time, but like I said, lots of people are counting on this! Thanks!
09-09-2000, 12:15 PM
Try adding the code in the keypress event to see if it makes any differece.
If it doesn't, you could always use one HUGE Secelt Case statemt.
Select Case KeyWord