|
-
February 22nd, 2000, 02:49 PM
#1
WSH
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
-
February 23rd, 2000, 03:42 AM
#2
Re: WSH
my very personal comments:
- I'd rather use PERL to do the conversion; it' ll probably take only 5 % of the required lines of code.
- you should take comment lines into account
- AFAIK VBSCript does not support Declare statements, as well as Public and so on.
You might wanna check for these (and issue warnings?)
First of all, why convert BASs to VBS, when you can Createobject?
I'd rather leave my VB COM objects as they are and use them from WSH.
-
February 23rd, 2000, 07:44 AM
#3
Re: WSH
Thanks for your comments. You're right about the declare statements, and I'll have to double check on the Public thing. The reason I want to convert BASs to VBS is that I have to write VBS scripts for a lot of administrative tasks where I cannot send libraries that need registered on the target machine. I'm using WSH as an advanced replacement for BAT files. Unfortunately, VB has made me lazy over the years and I would much rather have things like auto-complete than keep an object model handy to double check what methods and properties I have available to me. As for the PERL thing, I never learned it. Is it difficult to learn?
-
February 23rd, 2000, 07:47 AM
#4
Re: WSH
PERL is one of the most widely used scripting language on the Web as far as I know.
Is it easy? kind of.
But, it offers so many different ways to solve problems that you could say:
it's fairly easy to learn, but it can be extremely hard to read (and understand) someone else's scripts.
-
February 23rd, 2000, 07:48 AM
#5
Re: WSH
one more idea: wouldn't it be cool to have a VB Add-in that would convert the current module into a VBS file?
-
February 23rd, 2000, 07:52 AM
#6
-
February 23rd, 2000, 07:55 AM
#7
Re: WSH
i'm sure this is a blatently obviose question to all you pros, but is it possible to MAKE vb add-ins?
-
February 23rd, 2000, 07:58 AM
#8
Re: WSH
>but is it possible to MAKE vb add-ins?
it sure is. I have written a couple of them.
VB 6 comes even with a project type of Add-in that you can select, when you choose File/New Project...
-
February 23rd, 2000, 08:30 AM
#9
Re: WSH
PERL is great for handling text processing / formatting - like Lothar says, it's quite easy to learn, but some programmers (probably those with a 'C' Background) like to cram as many statements onto one line as possible, making it a nightmare to read some programs.
BTW, I seem to remember that you can get PERL as a 'plugin' language for the WSH - anyone else heard anything about this ?
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
-
February 23rd, 2000, 08:34 AM
#10
Re: WSH
WSH is - as its name implies - a scripting host.
Thus you can "plug in" any Activex Scripting language, such as Pythonscript and YES, PERLScript.
This is about the same technology that you can use in IE scripting. IE can also "run" Perlscripts (IE does, of course not run it, but rather host the scripting engine).
-
February 23rd, 2000, 08:39 AM
#11
Re: WSH
>some programmers (probably those with a 'C' Background) like to cram as many statements onto one line as possible, making it a nightmare to read some programs
there is a philosophy in our department (more like a joke): if your PERL script doesn't fit onto one line, you haven't really exploited the full functionality of the language :-)
-
February 23rd, 2000, 09:16 AM
#12
Re: WSH
Caught a major oversight on this. In removing the type in my variable declarations, I killed functions.
Function MyFunc(Expression as string) as string
Would be hosed beyond belief
Function MyFunc(Expression
-
February 23rd, 2000, 11:10 AM
#13
Re: WSH
BTW, here is a PERL script that does what your VBScript does:
s/(Dim |Public |Private )(\w+) As.*/Dim \2/i;
s/(Private|Public) (Sub|Function .*)/\2/i;
s/CreateObject\("(.*)"\)/WScript.CreateObject("\1"/gi;
if( /^Attribute.*/ ) {} else { print; }
...it even takes care of Private and Public declares...
still far from being perfect, but it might give you an idea of the power of PERL.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|