View Full Version : Converting VB code to HTML
Does anyone know how to keep the correct formating of VB code when you put it on webpage. You know, the different colours for each type of object, etc. My knowledge of HTML is limited, but I assume this could be done by a TAG or some sort of script.
Preferably, I would like to be able to convert existing VB objects, but I would be happy just to be able to copy and paste the existing code.
Thanks in advance for your help.
04-29-2003, 04:37 PM
Two ways of doing this. If it only a short bit of code, then enclosing it in "code" tags will preserve formatting, and display in a monospaced font. For a longer program listing, use the "pre" tags.
Thanks David, I will give that a try.
04-30-2003, 07:31 PM
< code > and < pre > are very different beasts. As the HTML specifications state, < pre > is used to indicate that a block of text is computer code. This is structural information, and it is entirely up to the user agent (the webbrowser) as to how to display it.
< pre >, in contrast, is a block level tag and carries more specific information for user agents. Generally browser will not wrap < pre > text and will preserve all white space formatting (like consecutive spaces, etc.)
AFAIK, colour-coding is not possible without some very specialized server setup, or without hacking your code with a lot of HTML tags. The exception to that is PHP, where it is possible without a lot of trouble to produce colour coding. But VB isn't PHP :)
I'd suggest you use < pre > and also ensure that your line-lengths don't exceed 80 characters. I don't know how MS does it, but in many programming languages a line of code can be broken across two lines by escaping the new line character(s) with a backslash, e.g.,
tar cz -T /backup/daily/$thisuser/$thisuser-$today.txt \
(Just something I grabbed from a backup script I was working on). Having all of that one command on a single line would mess up the display of this thread, causing it to stretch horizontally and scroll off-screen. That's why you want to break your lines of < pre > text.
(Edit) Or you could try this :)
Sleddog Thanks for that link.
I also found a little free application on the web which does the same thing, but instead of converting a form, you can copy and paste any code into and it will convert it for you.
Here is the link for anyone who is interested
Thanks for your help
05-03-2003, 07:23 PM
An standalone underscore _ is used to break lines of code in VB. He He :D (I think)!
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.