Results 1 to 13 of 13

Thread: vb code syntax highlighting?

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2003
    Posts
    40

    vb code syntax highlighting?

    this is baking my noodle!

    here and on code guru, i think they use the same boards, because when one is down, so is the other.. so here i was hoping to find the answer to:

    what is the vb tag to make code syntax highlighted?

    Code:
     merely puts things in black
    VB Code:
    1. appears not to be it,
    [vb] doesnt work (ala
    PHP Code:

    [/vb]

    [visualbasic]
    if then else 'guess
    [/visualbasic]

    [visual basic]
    if then else 'guess
    [/visual basic]

    [vb code]
    if then else 'guess
    [/vb code]

    [code language=vb]
    if then else 'guess
    [/code]

    VB Code:
    1. hello

  2. #2

    Thread Starter
    Member
    Join Date
    Oct 2003
    Posts
    40
    ahhh

    vbcode.

    that doesnt work on codeguru forums, so how do people there get it highlighted?

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. 'this seems to work for me
    2. If youuse=[ vbcode ] - spaces Then
    3.   Success=True
    4. End If

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    I think it is case sensitive :

    VB Code:
    1. If Then
    2. if then


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I can't speak for how to do it on CodeGuru, but here it is [vbcode][/vbcode] or the new VB button, and yes, it's case sensitive, but then again if you think about it so is VB. VB however will capitalize things for you when necessary and I don't think you can expect simple tags to have that functionality.

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by MartinLiss
    and I don't think you can expect simple tags to have that functionality.
    Oh yes you can!

    If I could see how the vbcode tag works, I could probably tweak it to automatically capitalize words. I'm sure it just uses a preg_replace() or something in PHP, so it would quite easy to make it capitalize them.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Exactly. If it's a regular expression, and there's an array of key words to colorize, you could loop the array, colorizing each keyword, and replacing the original word with the properly cased keyword from the array.

    Sorry if that's confusing. Using a loop might slow it down a bit, so I'd have to test it to be sure...and I know you guys don't like modifying the board code because of updates and having to redo it...but I'm just saying...it's possible, and quite easy.

    That's all.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm not sure I know what you're talking about, Martin?

    I figured there would be an array of keywords in the php code that it's using to search the post text and then colorize accordingly, probably using regular expressions and the preg_replace() function in PHP.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    This is just assuming that vBulletin does it this way.

    Code:
    <?php
    
        // Setup keyword array:
        $keywords = array('If', 'End If', 'Then', 'End', 'Dim', 'As', 'Integer', 'String', 'Function', 'Sub');
    
        // Setup example text:
        $post_text = 'dim x as integer
        if x > 10 then
            Text1.Text = "Number is too large!"
        end if';
    
        // Format the array:
        array_walk($keywords, 'formatItem');
        // Colorize the keywords:
        $formatted_text1 = preg_replace($keywords, '<span style="color: #0000a0;">\\1</span>', $post_text);
        // Ouput the text:
        echo '<hr /><pre>' . nl2br($formatted_text1) . '</pre><hr />';
    
    
        // NEW CAPITALIZATION METHOD:
    
        // Setup the array:
        $keywords = array('If', 'End If', 'Then', 'End', 'Dim', 'As', 'Integer', 'String', 'Function', 'Sub');
    
        // Loop the example text, colorize and replace keywords:
        $formatted_text2 = $post_text;
        for ($i = 0; $i < count($keywords); $i++) {
            $formatted_text2 = preg_replace('/(' . $keywords[$i] . ')/i', 
                '<span style="color: #0000a0;">' . $keywords[$i] . '</span>', $formatted_text2);
        }
    
        // Ouput the text:
        echo '<hr /><pre>' . nl2br($formatted_text2) . '</pre><hr />';
    
    
        // Function used in first example:
        function formatItem(&$item, $key) {
            $item = "/($item)/i";
        }
    ?>
    I know that's probably all gibberish to anyone who doesn't know PHP, but you can see the output here (ignore the double-spacing problem).
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Now that I think of it, maybe vBulletin just doesn't colorize based on case insensitivity. If that's the case, it'd be easy to make it colorize the lowercase words, but they would then stay lowercase.

    Again, I'm not sure since I don't know how vBulletin does it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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