VBS2Html Converter 
Author Message
 VBS2Html Converter

Very cool!

Where you check args for a filename:

' the file to convert
Set oArgs = WScript.Arguments
 If oArgs.Count = 0 Then
     MsgBox "No file to convert!"
     WScript.Quit
 End If
strInputFile = oArgs.Item(0)

I like to instead ask for the filename if it's not already in the arguments.
Then I can either use this script ineractively OR programmatically:

If WScript.Arguments.Count < 1 Then
 strInputFileName = InputBox("Enter name of file you want converted:", "VBS
to HTML")
Else
 strInputFileName = WScript.Arguments(0)
End If


Quote:
> Here is a cool script that I wrote, it outputs a VBS script to HTML with
> Syntax Coloring of keywords,constants,strings and comments.  Great for
> viewing VBScripts!
> After all, Notepad is not the worlds greatest program for viewing scripts.

> Enjoy,
> Jeff



Sun, 14 Jul 2002 03:00:00 GMT  
 VBS2Html Converter


Quote:
>Here is a cool script that I wrote, it outputs a VBS script to HTML with
>Syntax Coloring of keywords,constants,strings and comments.  Great for
>viewing VBscripts!
>After all, Notepad is not the worlds greatest program for viewing scripts.

I've modified it to process JScript files.  I think that someone could easily turn this
into a utility for any file (i.e. for .wsf files).

----------------------------------------------------------------
'====================================================================
' JS2Html.vbs
' -----------
'
' Usage: [host] js2html.vbs [file]
'
' host  Script host executable.  Not needed for NT/2000
'
' file  File to process.
'
'====================================================================

Dim oFS,oInputFile,oOutputFile,sWord,oArgs
Dim iLength,iPos,sString,sOutString,oWShell,strInputFile

Dim aKeyWords
Dim aConstWords

If WScript.Arguments.Count < 1 Then
 strInputFile = InputBox("Enter name of file you want converted:", "JScript to HTML")
Else
 strInputFile = WScript.Arguments(0)
End If

'===============================================================
' Colour definitions
'===============================================================

Const clrComment = "#2e8b57"    ' green
Const clrString  = "#000080"    ' navy blue
Const clrKeyword = "#0000ff"    ' blue
Const clrObject = "#ff00ff"     ' purple
Const clrConstant= "#dc143c"    ' red

'===============================================================
' Keywords
'===============================================================

aKeyWords = Array("function","new","for","while","do","var","typeof","if")

aConstWords = Array("true","false","null")

aObjectWords=Array("Date","ActiveXObject","Object","String","window","self",_
"document","navigator","WScript")

'===============================================================
' Script...

Set oFS = CreateObject("Scripting.filesystemobject")
Set oOutputFile = oFS.CreateTextFile("c:\htmlout.htm",True,False)
Set oInputFile = oFS.OpenTextFile(strInputFile,1,False)

oOutputFile.WriteLine "<html>"
oOutputFile.Write "<pre>"
Do While Not oInputFile.AtEndOfStream
sString = oInputFile.ReadLine
iLength = Len(sString)
iPos = 0
Do While True
If Left(Trim(sString),2)="//" Then
sOutString = HTMLColorString(sString,clrComment)
sWord = sString
Else
sWord = GetNextWord(sString)
If sWord = "" Then
If iPos <= iLength Then
If sString = "" Then Exit Do
sWord = Mid(sString,1,1)
If sWord = Chr(34) Then
For i = 2 To iLength
If Mid(sString,i,1) = Chr(34) Then
Exit For
End If
Next
sWord = Left(sString,i)
sOutString = HTMLColorString(sWord,clrString)
sString = Mid(sString,i+1,Len(sString))
Else
If sWord = Chr(9) Then
sOutString = "   "
sString = Right(sString,Len(sString)-1)
Else
sOutString = sWord
sString = Right(sString,Len(sString)-1)
End If
End If
Else
Exit Do
End If
Else
sString = Mid(sString,Len(sWord)+1,Len(sString))
If IsKeyWord(sWord) Then
sOutString = HTMLColorString(sWord,clrKeyWord)
ElseIf IsConstant(sWord) Then
sOutString = HTMLColorString(sWord,clrConstant)
ElseIf IsObject(sWord) Then
sOutString = HTMLColorString(sWord,clrObject)
Else
sOutString = sWord
End If
End If
End If
oOutputFile.Write sOutString
iPos=iPos+Len(sWord)
If iPos >= iLength Then
Exit Do
End If
Loop
oOutputFile.Write vbCrLf
Loop

oOutputFile.Write "</pre>"
oOutputFile.WriteLine "</html>"
oInputFile.Close
oOutputFile.Close

Set oWShell = CreateObject("wscript.shell")
oWShell.Run "c:\htmlout.htm"
WScript.Quit

Function GetNextWord(sString)
Dim i,sWord
For i = 1 To Len(sString)
If Instr(1,"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ_",Mid(sString,i,1),1) = 0 Then
Exit For
End If
sWord = sWord + Mid(sString,i,1)
Next
GetNextWord = sWord
End Function

Function IsKeyWord(sWord)
Dim lRet
lRet=False
For i = 0 To UBound(aKeyWords)
If aKeyWords(i) = sWord Then
lRet = True
Exit For
End If
Next
IsKeyWord = lRet        
End Function

Function IsConstant(sWord)
Dim lRet
lRet=False
For i = 0 To UBound(aConstWords)
If aConstWords(i) = sWord Then
lRet = True
Exit For
End If
Next
IsConstant = lRet      
End Function

Function IsObject(sWord)
Dim lRet
lRet=False
For i = 0 To UBound(aObjectWords)
If aObjectWords(i) = sWord Then
lRet = True
Exit For
End If
Next
IsObject = lRet
End Function

Function HTMLColorString(szString,szColor)
HTMLColorString = "<b><FONT color="+Chr(34)+szColor+Chr(34)+">"+szString+"</b></FONT>"
End Function
----------------------------------------------------------------

--
Robert Bradley

I am not a mindreader, so I don't know everything.



Wed, 17 Jul 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VBS2Html Converter

2. VBS2Html Converter

3. VBS2Html Converter

4. Converter to converter converters?

5. Excel 2000 File Converters

6. WordPro-converter

7. File Converters in Word Macros

8. File Converter

9. unicode UTF-8 converter

10. Export filter/converter

11. file converter

 

 
Powered by phpBB® Forum Software