AutoIt Forums: VBScript to AutoIt Converter - AutoIt Forums

Jump to content

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

VBScript to AutoIt Converter VBScript to AutoIt Converter Rate Topic: ***** 3 Votes

#1 User is offline   bkemmler 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 12
  • Joined: 18-January 05
  • Location:Germany

Posted 04 June 2005 - 11:40 AM

This is a converter for a VBScript (5.6) to AutoIt (3.1.1) converter.

i hope it is useful.

There are many thinks to add at the moment.

To test it you need all attach files.

Comments are welcome.

Version 0.4
- Fixing error message in GUI
- Workaround for wscript.echo
- Better handling of parenthesis for sub's
- Implement ReDim
- Set default destination file name in gui
- Added some new commands in VATable.txt
- Improvements for select constructs

Version 0.3
- Added command line switch (vaconvert VBSCRIPTFILE)
- Added Gui to select source and destination file (tahnks to gafrost)
- Better handlung for prodedure calls
- Fixing other errors (e.g. endless loop)

Version 0.2
- Add some simple replace commands (VATable.txt)
- Improve Select case
- Find variables without Dim
- Find Constants
- Add List of VBCommands (VACommands.txt)

Version 0.1
- Better function handling
- Added most VBScript functions
- Include handling

Version 0.01
- First public release

Added v0.4 10.06.2005
Added v0.3 08.06.2005
Added v0.2 06.06.2005
Added v0.1 05.06.2005
Added v0.01 04.06.2005

Attached File(s)


This post has been edited by bkemmler: 10 June 2005 - 07:52 AM


#2 User is offline   SumTingWong 

  • My custom member title
  • PipPipPipPip
  • Group: Full Members
  • Posts: 360
  • Joined: 05-April 04
  • Location:London, UK

Posted 04 June 2005 - 12:12 PM

bkemmler, on Jun 4 2005, 10:40 AM, said:

This is the first public release (v0.02) of a VBScript (5.6) to AutoIt (3.1.1) converter.

i hope it is useful.

There are many thinks to add at the moment.

To test it you need all attach files.

Comments are welcome.


Very nicely done! :thumbsup:

#3 User is offline   bkemmler 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 12
  • Joined: 18-January 05
  • Location:Germany

Posted 04 June 2005 - 09:53 PM

Wus, on Jun 4 2005, 09:11 PM, said:

can it goes from autoit to VB as well?
because although I dont know vb I do know autoIT and VB is necessary for some things



No it is only converting from VBScript to AutoIt.

Everything you want to do with VBScript should be possible with AutoIt

#4 User is offline   GaryFrost 

  • I don't need your attitude. I have one of my own
  • Icon
  • Group: Developers(Dev)
  • Posts: 7,854
  • Joined: 01-June 04
  • Gender:Male
  • Location:USA

Posted 05 June 2005 - 05:13 AM

Thought it could use a little gui interface, this was quick and dirty

[ code='text' ]    ( ExpandCollapse - Popup )
; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.1.1 ; Author:         Bernd Kemmler ; ; Script Function: ;    Convert VBScript to AutoIt 3.1.1 ; ; Version 0.02 ; ---------------------------------------------------------------------------- ; To Do: ; o Special handling of:  SELECT, Func Return, Class Blocks, Dim, Do loop, Redim, Function ; o GUI to select the source, destination ; o include handling ; ... ;Options #region Options #NoTrayIcon AutoItSetOption("MustDeclareVars", 1) AutoItSetOption("RunErrorsFatal", 0) AutoItSetOption("TrayIconHide", 1) ; Variable declarations #region Variables Global Const $strVersion = "0.02" Global Const $strMask = "#" Global Const $strRemark = "'" Global Const $strSpecial = ".,()<>=" Global $arrVBFile Global $arrVBFileMarked Global $arrAU3File Dim $Lbl_Source, $Lbl_Dest, $Btn_Source, $Btn_Dest, $Btn_Convert, $Btn_Exit, $msg #endregion ; Include files #region Includes #include <bk-array.au3> #include <bk-file.au3> #include <bk-string.au3> #include <array.au3> #include <math.au3> #endregion #region --- GuiBuilder code Start --- ; Script generated by AutoBuilder 0.5 Prototype #include <GuiConstants.au3> GuiCreate("Convert VBScript to AutoIt 3.1.1++", 500, 208) $Lbl_Source = GuiCtrlCreateLabel("Source File", 30, 30, 400, 20) $Lbl_Dest = GuiCtrlCreateLabel("Destination File", 30, 70, 400, 20) $Btn_Source = GuiCtrlCreateButton("Select...", 420, 20, 70, 30) $Btn_Dest = GuiCtrlCreateButton("Select...", 420, 60, 70, 30) $Btn_Convert = GuiCtrlCreateButton("Convert", 154, 130, 70, 30) $Btn_Exit = GuiCtrlCreateButton("Exit", 264, 130, 70, 30) GuiSetState() While 1     $msg = GuiGetMsg()     Select     Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit         ExitLoop     Case $msg = $Btn_Source         GUICtrlSetData($Lbl_Source,FileOpenDialog ( "Select VBS Source File", ".", "VBS (*.vbs)" , 3 ))     Case $msg = $Btn_Dest         GUICtrlSetData($Lbl_Dest,FileOpenDialog ( "Select Au3 Dest File", ".", "AutoIt (*.au3)" ))     Case $msg = $Btn_Convert         Convert(GUICtrlRead($Lbl_Source),GUICtrlRead($Lbl_Dest))     EndSelect WEnd Exit #endregion --- GuiBuilder generated code End --- Func Convert($Source, $Dest)     ReadVBFile($Source)     MarkSpecialParts()     ReplaceSimpleCommands()     ChangeVariables()     WriteAU3File($Dest) EndFunc

This post has been edited by gafrost: 05 June 2005 - 05:16 AM


#5 User is offline   bkemmler 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 12
  • Joined: 18-January 05
  • Location:Germany

Posted 05 June 2005 - 09:05 PM

Thanks for the GUI. I will include it in the next version. At the moment it is faster for the testing to just use test.vbs.

#6 User is offline   MSLx Fanboy 

  • Local $Clue = 0
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,046
  • Joined: 24-January 05
  • Location:Orlando, FL

Posted 05 June 2005 - 10:18 PM

Wow am I slow, I just realized that i need the commands.txt file as well :P

Also, are there plans to automatically change the variable into the $variable_name format?

#7 User is offline   steve8tch 

  • Spammer!
  • PipPipPip
  • Group: Full Members
  • Posts: 283
  • Joined: 03-December 03

Posted 06 June 2005 - 01:07 AM

Can I throw a spanner in to the works..... :evil:

I just found a relatively simple vbs script to do a test.
The converted script still needs alot of work done to make it usable in Aut3.
Am I doing it right!
I wasn't too sure what I was supposed to do with the commands.txt
Here is my test vbs script - can you check if it works OK for you.


[ code='text' ]    ( ExpandCollapse - Popup )
' FreeSpace.vbs,  Version 1.00 ' Display free disk space for all local drives. ' ' Written by Rob van der Woude ' http://www.robvanderwoude.com ' Check command line parameters Select Case WScript.Arguments.Count     Case 0         ' Default if none specified is local computer (".")         Set objWMIService = GetObject( "winmgmts://./root/cimv2" )         Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )         For Each objItem in colItems             strComputer = objItem.Name         Next     Case 1         ' Command line parameter can either be a computer name         ' or "/?" to request online help         strComputer = Wscript.Arguments(0)         if InStr( strComputer, "?" ) > 0 Then Syntax     Case Else         ' Maximum is 1 command line parameter         Syntax End Select Display( strComputer ) WScript.Quit(0) Function Display( strComputer )     strMsg = vbCrLf & "Name:" & vbTab & "Drive:" & vbTab & "Size:" & _              vbTab & "Free:" & vbTab & "% Free:" & vbCrLf & "=====" & _              vbTab & "======" & vbTab & "=====" & vbTab & "=====" & _              vbTab & "=======" & vbCrLf     On Error Resume Next     Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )     If Err.Number Then         WScript.Echo vbCrLf & "Error # " & CStr( Err.Number ) & _                      " " & Err.Description         Err.Clear         Syntax     End If     On Error GoTo 0     ' Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where MediaType=12",,48)     Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where DriveType=3",,48)     For Each objItem in colItems         strMsg = strMsg & strComputer & vbTab & _                  objItem.Name & vbTab & _                  CStr( Int( 0.5 + ( objItem.Size / 1073741824 ) ) ) & _                  vbTab & _                  CStr( Int( 0.5 + ( objItem.FreeSpace / 1073741824 ) ) ) & _                  vbTab & _                  CStr( Int( 0.5 + ( 100 * objItem.FreeSpace / objItem.Size) ) ) & _                  vbCrLf     Next     WScript.Echo strMsg End Function Sub Syntax     strMsg = vbCrLf & "FreeSpace.vbs,  Version 1.00" & vbCrLf & _              "Display free disk space for all local drives." & vbCrLf & _              vbCrLf & _              "Usage:  CSCRIPT  FREESPACE.VBS  [ computer_name ]" & _              vbCrLf & vbCrLf & _              "Where:  " & Chr(34) & "computer_name" & Chr(34) & _              " is the name of a WMI enabled computer on the network" & _              vbCrLf & vbCrLf & _              "Written by Rob van der Woude" & vbCrLf & _              "http://www.robvanderwoude.com" & vbCrLf     WScript.Echo strMsg     WScript.Quit(1) End Sub


Thanks

#8 User is offline   MSLx Fanboy 

  • Local $Clue = 0
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,046
  • Joined: 24-January 05
  • Location:Orlando, FL

Posted 06 June 2005 - 01:18 AM

I was working on my own script, and the WScript.Echo wasn't being translated...I don't know if it was just my script or...

#9 User is offline   bkemmler 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 12
  • Joined: 18-January 05
  • Location:Germany

Posted 06 June 2005 - 05:52 AM

steve8tch, on Jun 6 2005, 01:07 AM, said:

Can I throw a spanner in to the works..... :evil:

I just found a relatively simple vbs script to do a test.
The converted script still needs alot of work done to make it usable in Aut3.
Am I doing it right!
I wasn't too sure what I was supposed to do with the commands.txt
Here is my test vbs script - can you check if it works OK for you.


Thanks


You are right. With this kind of script it will have problems. The actual version needs DIM's for the variables.

#10 User is offline   bkemmler 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 12
  • Joined: 18-January 05
  • Location:Germany

Posted 06 June 2005 - 05:55 AM

MSLx Fanboy, on Jun 6 2005, 01:18 AM, said:

I was working on my own script, and the WScript.Echo wasn't being translated...I don't know if it was just my script or...


There is no command like WScript.Echo in AutoIt. And if you do not want to use WSH, it is not a good idea to use the WScript object.

#11 User is offline   bkemmler 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 12
  • Joined: 18-January 05
  • Location:Germany

Posted 06 June 2005 - 05:56 AM

MSLx Fanboy, on Jun 5 2005, 10:18 PM, said:

Wow am I slow, I just realized that i need the commands.txt file as well :P

Also, are there plans to automatically change the variable into the $variable_name format?


If you use the DIM command in VBScript it is working already.

#12 User is offline   bkemmler 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 12
  • Joined: 18-January 05
  • Location:Germany

Posted 06 June 2005 - 02:36 PM

Version 0.2 Release

#13 User is offline   ptrex 

  • Mass Spammer!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 2,272
  • Joined: 03-June 05

Posted 06 June 2005 - 05:00 PM

Hello,

Downloaded the new version and ran it with AutoIT version 3.1.1.41 Alpha.

But nothing happenes ?

When running the VACONVERT.AU3 I expected a Gui to come up, is that correct ?

#14 User is offline   MSLx Fanboy 

  • Local $Clue = 0
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,046
  • Joined: 24-January 05
  • Location:Orlando, FL

Posted 06 June 2005 - 08:44 PM

i believe right now it only converts a file called 'test.vbs' located in the scripts directory.

As for WScript.Echo, can't you just do 'MsgBox(0, "", $variable)'?

This post has been edited by MSLx Fanboy: 06 June 2005 - 08:45 PM


#15 User is offline   ptrex 

  • Mass Spammer!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 2,272
  • Joined: 03-June 05

Posted 07 June 2005 - 07:52 AM

This script might be useful.

But untill there is no readme file, explaining on how to use it, it is NOT useful.

Hopefully more help is on the way.

#16 User is offline   bkemmler 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 12
  • Joined: 18-January 05
  • Location:Germany

Posted 08 June 2005 - 08:34 PM

ptrex, on Jun 7 2005, 07:52 AM, said:

This script might be useful.

But untill there is no readme file, explaining on how to use it, it is NOT useful.

Hopefully more help is on the way.


There is a gui now available. I hope this helps.

#17 User is offline   bkemmler 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 12
  • Joined: 18-January 05
  • Location:Germany

Posted 08 June 2005 - 08:34 PM

Version 0.3 can be downloaded

#18 User is offline   ptrex 

  • Mass Spammer!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 2,272
  • Joined: 03-June 05

Posted 09 June 2005 - 08:13 AM

@bkemmler

Thanks for the new version. Now help file needed anymore since the GUI runs OK.

I tested a VBscript which should show the OS version of your system.
The converion was done 95 % OK.

Which is a pretty good job.

The only thing you need to build in into you conversion is the translation from Wscript.Echo -> Msgbox to show the output.

At the moment there is no output after the conversion.
[ code='text' ]    ( ExpandCollapse - Popup )
Vbscript : 'Returns the name and version number of the operating system installed on a computer. strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _     ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems     Wscript.Echo objOperatingSystem.Caption & " " & _         objOperatingSystem.Version Next AuITScript: ;Returns the name and version number of the operating system installed on a computer. $strComputer = "."  $objWMIService = ObjGet("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")  $colOperatingSystems = $objWMIService.ExecQuery _     ("Select * from Win32_OperatingSystem") For $objOperatingSystem in $colOperatingSystems ;VA  Wscript.Echo $objOperatingSystem.Caption & " " & _         $objOperatingSystem.Version() Next SEE COMMENT;VA where there has been no translation done !!



This should have been :

[ code='text' ]    ( Popup )
Msgbox(0, "VBScript to AutoIt Converter v0.3", $objOperatingSystem.Caption & " " & $objOperatingSystem.Version())


I hope this feedback helps you improving.
It only needs a little bit extra tweaking.

Keep up the good work !!

#19 User is offline   GaryFrost 

  • I don't need your attitude. I have one of my own
  • Icon
  • Group: Developers(Dev)
  • Posts: 7,854
  • Joined: 01-June 04
  • Gender:Male
  • Location:USA

Posted 09 June 2005 - 12:28 PM

Personally I would rather the WScript.Echo get converted to ConsoleWrite.

#20 User is offline   ptrex 

  • Mass Spammer!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 2,272
  • Joined: 03-June 05

Posted 09 June 2005 - 12:40 PM

@gafrost
@bkemmler

The explanation in the help, of the ConsoleWrite is :

Quote

Writes data to a stream that text editors can SOMETIMES read.


- The first reason whu this should not be shosen is of the SOMETIMES possibility.
If you like this option VBscript has an other command that produces output to
console. This command should than be translated to ConsoleWrite.

- The second reason not to choose this is, that not an exact conversion of how the
behaviour was in VBscript

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users