Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - [ann] code sample to convert html to vb or vbs...

Reply
 
Old 07-07-2008   #1 (permalink)
mr_unreliable


 
 

[ann] code sample to convert html to vb or vbs...

hi groupies,

o.k., so this is pretty trivial, but may save somebody
the 10 minutes or so that it would take to write for
yourself.

There are some webpages which present sample code which is
embedded in "pre" tags -- and so the lines don't end with
vbCrLf's, rather they end with "br" tags. Also, there are
other re-codings, such as the ampersand, less than,
greater than, and etc.

Here is the code used to convert some (html-formatted)
source code back into vb/vbs source. The procedure was
to "view source" on the html page showing the code, extract
the text inside the "pre" tags, and then run this:

--- <code> ---
Const htmlFile = "callDLL_Example1.txt"
Const basFile = "callDLL_Example1.bas"

Const ForReading = 1, ForWriting = 2
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile : Set oFile = fso.OpenTextFile(htmlFile, ForReading)
Dim fHTML : fHTML = oFile.ReadAll


Dim fBAS
fBAS = Replace(fHTMl, "<br>", vbCrLf)
fBAS = Replace(fBAS, "&nbsp; ", " ")
fBAS = Replace(fBAS, "&nbsp;", " ")
fBAS = Replace(fBAS, "&amp;", "&")
fBAS = Replace(fBAS, "&lt;", "<")
fBAS = Replace(fBAS, "&gt;", ">")
Set oFile = fso.OpenTextFile(basFile, ForWriting, True)
oFile.Write fBAS
oFile.Close

MsgBox("finished")
WScript.Quit
--- </code> ---

As you can probably tell, the script assumes that all the
relevant files (including the script itself) are all
located in the current working directory.

cheers, jw

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Can I code HTML code straight to Webbrowser control? .NET General
Script-based code sample library (HTA) VB Script
Need specific WCF code sample .NET General
Efficiency in my sample code PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46