|
-
Apr 17th, 2002, 10:48 AM
#1
Thread Starter
New Member
Visual Basic Code Coloring
Somebody knows where I can get such a script.
-
Apr 18th, 2002, 03:34 PM
#2
-
Apr 18th, 2002, 04:09 PM
#3
Member
If it's any help, here's a vBulletin hack, same as the one used here to make [Highlight=VB]: http://www.vbulletin.org/forum/showt...ghlight=vbcode
-
Apr 18th, 2002, 08:29 PM
#4
that's it arien give him a link he can't see. good job
-
Apr 18th, 2002, 09:28 PM
#5
Stuck in the 80s
I created a program that does this and converts it to HTML. The thing is, it'd have to be predone.
But basically what I did was.
Replace occurances of '.', '(', and ')' with spaced versions, ie ' . ', ' ( ', and ' ) '. After that I split up the string of code by newline characters. Than I ran each line through code, split it using a space (" ") as a deliminator. I then cycled through each word in the sentence and compared it to an array of reserved words, if they matched it through tags on the beginning and end, and did nothing if it didnt. It built the line back up as it went through each word, then also built the whole chunk of code back up as it finished each line.
Finally, I replaced the ' . ', ' ( ', and ' ) ' back with '.', '(', and ')'
If you don't understand anything I said, then just forget it all and don't try to understand.
-
Apr 18th, 2002, 10:06 PM
#6
Stuck in the 80s
Here's a start. See what you can do with this:
PHP Code:
<?php
$code = "Private Sub Form_Load()\nDim x As Integer";
$reserved = Array("Private", "Sub", "Dim", "As", "Integer");
$numr = count($reserved);
$lines = explode("\n", $code);
$numl = count($lines);
//for each line
for ($i = 0; $i < $numl; $i++) {
$words = explode(' ', $lines[$i]);
$numw = count($words);
$line = '';
//for each word
for ($j = 0; $j < $numw; $j++) {
$b = 0;
//for each reserved word
for ($k = 0; $k < $numr; $k++) {
if ($words[$j] == $reserved[$k]) {
$b = 1;
$line = $line . '<font color="blue">' . $words[$j] . ' </font>';
}
}
if ($b != 1) {
$line = $line . $words[$j] . ' ';
}
}
$fcode = $fcode . $line . "<br>";
}
echo $fcode;
?>
-
Apr 18th, 2002, 10:18 PM
#7
Stuck in the 80s
I just added a little to handle commments. Maybe someone can make this more efficient:
PHP Code:
<?php
$code = "Private Sub Form_Load()\nDim x As Integer\n 'this is our sample comment\n\nEnd Sub";
$reserved = Array("Private", "Sub", "Dim", "As", "Integer", "End");
$numr = count($reserved);
$code = str_replace('(', ' ( ', $code);
$code = str_replace(')', ' ) ', $code);
$code = str_replace('.', ' . ', $code);
$code = str_replace("'", " ' ", $code);
$lines = explode("\n", $code);
$numl = count($lines);
//for each line
for ($i = 0; $i < $numl; $i++) {
$words = explode(' ', $lines[$i]);
$numw = count($words);
$line = '';
//for each word
for ($j = 0; $j < $numw; $j++) {
$b = 0;
if($words[$j] == "'") {
$line = $line . '<font color="green">';
for ($m = $j; $m < $numw; $m++) {
$line = $line . $words[$m] . ' ';
}
$line = $line . "</font>";
break;
}
//for each reserved word
for ($k = 0; $k < $numr; $k++) {
if ($words[$j] == $reserved[$k]) {
$b = 1;
$line = $line . '<font color="blue">' . $words[$j] . ' </font>';
}
}
if ($b != 1) {
$line = $line . $words[$j] . ' ';
}
}
$fcode = $fcode . $line . "<br>";
}
$fcode = str_replace(' ( ', '(', $fcode);
$fcode= str_replace(' ) ', ')', $fcode);
$fcode = str_replace(' . ', '.', $fcode);
$fcode = str_replace(" ' ", "'", $fcode);
echo "<pre>$fcode</pre>";
?>
Let me know if this helps or if you need anything more.
-
Apr 19th, 2002, 05:31 AM
#8
Conquistador
don't you hate reformatting and not backing up :O
i had written a function for this, don't know where it is now and can't be bothered to re write D:
-
Apr 19th, 2002, 02:35 PM
#9
Thread Starter
New Member
Thx for all your replies. I know I can make something myself, but I'm just to lazy to make a good script for this. It's even for myself but for somebody elses site. I was just curious if I could down this script somewhere, but it turns out I can't..
Thx again
-
Apr 19th, 2002, 02:43 PM
#10
Stuck in the 80s
Is there something wrong with the code I posted above?
-
May 5th, 2002, 12:02 PM
#11
-
May 5th, 2002, 02:41 PM
#12
Stuck in the 80s
Please post any inquires about my facial hair in the designated thread. Thank you.
-
May 5th, 2002, 02:56 PM
#13
lol, ill make sure to do that..hehe
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
|