Kyle Burns
February 22nd, 2000, 01:49 PM
I posted earlier asking about a script editor, then thought maybe I would write a routine to convert a .bas file to .vbs. I've written a routine to do this and would like to submit to see if anyone can see changes that would make this routine work better. I would appreciate any suggestions or comments and will graciously ignore any snide remarks :)
option Explicit
'bas2vbs.vbs
'converts bas file to vbs file for use
'with WSH
'NOTE: Still need to be careful to only use
'control structures and functions available in
'VBScript in your BAS
Dim oFS
Dim oFileIn
Dim oFileOut
Dim sFilePathIn
Dim sFilePathOut
Dim sLineText
sFilePathIn = InputBox("Enter Name of File to convert")
sFilePathOut = Left(sFilePathIn, Instr(sFilePathIn, ".")) & "vbs"
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
set oFileIn = oFS.OpenTextFile(sFilePathIn)
set oFileOut = oFS.CreateTextFile(sFilePathOut)
Do Until oFileIn.AtEndOfStream = true
sLineText = oFileIn.ReadLine()
If UCase(Left(sLineText, 9)) = "ATTRIBUTE" then sLineText = ""
Dim iPos
iPos = InStr(UCase(sLineText), " as ")
If iPos > 0 then
sLineText = Trim(Left(sLineText, iPos - 1))
End If
If Instr(UCase(sLineText), " CREATEOBJECT(") > 0 then
Dim sTemp
Dim arText
sTemp = ""
arText = Split(sLineText, " ")
Dim iCur
for iCur = LBound(arText) to UBound(arText)
If Left(UCase(arText(iCur)),12) = "CREATEOBJECT" then
sTemp = sTemp & "WScript." & arText(iCur)
else
sTemp = sTemp & arText(iCur)
End If
sTemp = sTemp & " "
next
sLineText = Trim(sTemp)
End If
If sLineText > "" then oFileOut.WriteLine sLineText
Loop
oFileIn.Close
oFileOut.Close
set oFileIn = nothing
set oFileOut = nothing
set oFS = nothing
option Explicit
'bas2vbs.vbs
'converts bas file to vbs file for use
'with WSH
'NOTE: Still need to be careful to only use
'control structures and functions available in
'VBScript in your BAS
Dim oFS
Dim oFileIn
Dim oFileOut
Dim sFilePathIn
Dim sFilePathOut
Dim sLineText
sFilePathIn = InputBox("Enter Name of File to convert")
sFilePathOut = Left(sFilePathIn, Instr(sFilePathIn, ".")) & "vbs"
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
set oFileIn = oFS.OpenTextFile(sFilePathIn)
set oFileOut = oFS.CreateTextFile(sFilePathOut)
Do Until oFileIn.AtEndOfStream = true
sLineText = oFileIn.ReadLine()
If UCase(Left(sLineText, 9)) = "ATTRIBUTE" then sLineText = ""
Dim iPos
iPos = InStr(UCase(sLineText), " as ")
If iPos > 0 then
sLineText = Trim(Left(sLineText, iPos - 1))
End If
If Instr(UCase(sLineText), " CREATEOBJECT(") > 0 then
Dim sTemp
Dim arText
sTemp = ""
arText = Split(sLineText, " ")
Dim iCur
for iCur = LBound(arText) to UBound(arText)
If Left(UCase(arText(iCur)),12) = "CREATEOBJECT" then
sTemp = sTemp & "WScript." & arText(iCur)
else
sTemp = sTemp & arText(iCur)
End If
sTemp = sTemp & " "
next
sLineText = Trim(sTemp)
End If
If sLineText > "" then oFileOut.WriteLine sLineText
Loop
oFileIn.Close
oFileOut.Close
set oFileIn = nothing
set oFileOut = nothing
set oFS = nothing