Results 1 to 13 of 13

Thread: Visual Basic Code Coloring

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    3

    Visual Basic Code Coloring

    Somebody knows where I can get such a script.

    Code:
    Dim blat as String
    VB Code:
    1. Dim blat as string

  2. #2
    scoutt
    Guest
    no you have to make it.

  3. #3
    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

  4. #4
    scoutt
    Guest
    that's it arien give him a link he can't see. good job

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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;
    ?>
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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);
    $fcodestr_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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    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:

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    3
    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

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Is there something wrong with the code I posted above?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    vshammas
    Guest
    The Hobo: I think youd look better without the pimpish-avatar anyway, I guess this doesn't have anything to do with the post, but just please change it btw, is that you w/ a photoshop edited mustache

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Please post any inquires about my facial hair in the designated thread. Thank you.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    vshammas
    Guest
    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
  •  



Click Here to Expand Forum to Full Width