Page 1 of 1

VBScript to PureBasic program code generator

Posted: Thu Mar 26, 2015 4:30 pm
by Ferdinand
This program creates a complete PureBasic program from a VBScript source.
The created pb-program uses Thomas "ts-soft" Schultz' ScriptControl library in include-file format.
I will post the source of the ScriptControl include directly under this one.

You will probably have to tweak the created pb-program a bit:
- you may want to use an IncludePath
- the procedure that processes the script (DoTheScript) returns a string, you may want to change that
- the ScriptControl functions for passing the output of the VBScript to the pb-program are:
SCtr_EvalNum, SCtr_EvalStr, SCtr_EvalStr_UNICODE ; in the created program you will see an example
of using SCtr_EvalStr: "SCtr_EvalStr(strMsg)", which you may want to change
- etc. according to what you need

Code: Select all

;
; VBS to PB prog version 1.1
; Ferdinand Schinkel
; Date: March 2015
; PureBasic version: 5.31
;

Global RecNum

Procedure.s ProcessInputRecord(Record$)
  If Len(LTrim(Record$))=0  
    ProcedureReturn ""
  EndIf
  For x=1 To Len(Record$)                               ; check for comment lines
    If Mid(Record$,x,1)="'": ProcedureReturn "": EndIf  ; get rid of comment line by jumping out with empty string
    If Not(Mid(Record$,x,1)=" " Or Asc(Mid(Record$,x,1))=9): Break: EndIf  ; take space and TAB into account
  Next x  
;  
  If FindString(Record$, "Wscript.Quit",1,#PB_String_NoCase): ProcedureReturn "": EndIf
  Record$=ReplaceString(Record$, "Wscript.Echo", "MsgBox",#PB_String_NoCase)
  Record$=ReplaceString(Record$, "Wscript.Arguments.Count", "Wscript_Arguments_Count",#PB_String_NoCase)
  Record$=ReplaceString(Record$, "Wscript.Arguments.Named.Count", "Wscript_Arguments_Named_Count",#PB_String_NoCase)
  Record$=ReplaceString(Record$, "Wscript.Arguments.UnNamed.Count", "Wscript_Arguments_UnNamed_Count",#PB_String_NoCase)
  Record$=ReplaceString(Record$, "Wscript.CreateObject", "CreateObject",#PB_String_NoCase)
  Record$=ReplaceString(Record$, "WScript.Shell", "Wscript.Shell",#PB_String_NoCase)
  Record$=ReplaceString(Record$, "WScript.Network", "Wscript.Network",#PB_String_NoCase)
  Record$=ReplaceString(Record$, "WScript", "WSCRIPT")
;  
  RecOut$="  code$ + " + Chr(34)
  For i=1 To Len(record$)
    If Mid(Record$,i,1)=Chr(34)
      k=0
      For j=i+1 To Len(Record$)
        If Mid(Record$,j,1)=Chr(34)
          k=j
          Break
        EndIf
      Next j
      If k=0
        ProcedureReturn ";starting quote in line "+Str(RecNum)+" with no ending quote - line skipped"
      EndIf
      If i <> 1: RecOut$ + Chr(34) + "+": EndIf
      RecOut$ + "Chr(34)+"+Chr(34)+Mid(Record$,i+1,k-i-1)+Chr(34)+"+Chr(34)"
      If Not k=Len(Record$)
        RecOut$ + "+" + Chr(34)
      EndIf
      i=k
    Else
      RecOut$ + Mid(Record$,i,1)
    EndIf
  Next i
  ;
  ; quote after the end of the line EXCEPT if the line ended with Chr(34)
  If Len(RecOut$)>=7
    If Mid(RecOut$,Len(RecOut$)-6,7)<>"Chr(34)"
      RecOut$ + Chr(34)
    EndIf
  EndIf
  ;
  RecOut$ + " + #CRLF$"
  ProcedureReturn RecOut$
EndProcedure

StandardFile$ = GetCurrentDirectory()    
Pattern$ = "VBS (*.vbs)|*.vbs|Text (*.txt)|*.txt|All files (*.*)|*.*"
Pattern = 0    ; use the first of the three possible patterns as standard
InputFile$ = OpenFileRequester("Choose the VBScript .vbs or text file to convert", StandardFile$, Pattern$, Pattern)
If InputFile$=""
  MessageRequester("Information", "The requester was canceled", 0) 
  End  
EndIf
If Not ReadFile(1, InputFile$)   ; if the file could be read, we continue...
  MessageRequester("Information","could not open the text file")
  End  
EndIf
;
InputFile$=GetFilePart(InputFile$)
FindPoint=FindString(InputFile$,".")
If FindPoint=0: FindPoint=Len(InputFile$)+1: EndIf
OutputFile$=GetCurrentDirectory()
OutputFile$+Mid(InputFile$,1,FindPoint-1)+".pb"

If Not CreateFile(2, OutputFile$)         
  MessageRequester("Information","could not create the output file!")
  End  
EndIf

WriteStringN(2, "")
WriteStringN(2, "; program created with VBS_to_PB_prog_converter") 
WriteStringN(2, "")
WriteStringN(2, "IncludePath "+Chr(34)+"..\..\RESOURCES\IncludeFiles\"+Chr(34)) 
WriteStringN(2, "IncludeFile "+Chr(34)+"ScriptControl.pbi"+Chr(34))
WriteStringN(2, "")
WriteStringN(2, "Procedure.s DoTheScript()")
WriteStringN(2, "  Protected code$")
WriteStringN(2, "  Protected Wscript_Arguments_Count")
WriteStringN(2, "  Protected Wscript_Arguments_Named_Count")
WriteStringN(2, "  Protected Wscript_Arguments_UnNamed_Count")
WriteStringN(2, "")
WriteStringN(2, "; WScript: VBScript files sometimes make use of the WScript (script root) object, for example in:") 
WriteStringN(2, ";          WScript.Echo, WScript.Quit, WScript.Arguments.Count, etc.;") 
WriteStringN(2, ";          however, when running VBScript with the ScriptControl the WScript object is not present;") 
WriteStringN(2, ";          the program has made workarounds for some of the common WScript properties and methods,") 
WriteStringN(2, ";          but when you see WSCRIPT (capital letters) in a code$-line, it means there is no workaround") 
WriteStringN(2, ";          and you may have to manually create a workaround yourself") 
WriteStringN(2, "")

RecNum=0
Repeat
  If Not Eof(1)
    FileRead$=ReadString(1)
    RecNum+1
    OutputRecord.s=ProcessInputRecord(FileRead$)
    If OutputRecord<>""
      WriteStringN(2, OutputRecord) 
    EndIf  
  EndIf  
Until Eof(1)

WriteStringN(2,"")
WriteStringN(2,"  ScriptControl_Init()")
WriteStringN(2,"  SCtr_Reset()")
WriteStringN(2,"  SCtr_SetLanguage("+Chr(34)+"VBScript"+Chr(34)+")")
WriteStringN(2,"  SCtr_AddCode(code$)")
WriteStringN(2,";the following line is just an example of returning a VBScript value to PureBasic")
WriteStringN(2,"  ReturnValue.s=SCtr_EvalStr("+Chr(34)+"strMsg"+Chr(34)+")")
WriteStringN(2,"  ScriptControl_End()")
WriteStringN(2,"")
WriteStringN(2,"  ProcedureReturn ReturnValue")
WriteStringN(2,"EndProcedure")
WriteStringN(2,"")
WriteStringN(2,"Debug DoTheScript()")
WriteStringN(2,"")
WriteStringN(2,"End")

MessageRequester("VBS conversion finished", "PureBasic program created: "+OutputFile$)

CloseFile(1)
CloseFile(2)
End


Re: VBScript to PureBasic program code generator

Posted: Thu Mar 26, 2015 4:31 pm
by Ferdinand
the ScriptControl source (save as ScriptControl.pbi)

Code: Select all


; ScriptControl by Thomas 'ts-soft' Schulz

Interface IScriptControl Extends IDispatch
  get_Language(a)
  put_Language(strLanguage.p-bstr)
  get_State(a)
  put_State(a)
  put_SitehWnd(a)
  get_SitehWnd(a)
  get_Timeout(timeout)
  put_Timeout(timeout)
  get_AllowUI(a)
  put_AllowUI(a)
  get_UseSafeSubset(a)
  put_UseSafeSubset(a)
  get_Modules(a)
  get_Error(a)
  get_CodeObject(a)
  get_Procedures(a)
  _AboutBox()
  AddObject(a,b,c)
  Reset()
  AddCode(source.p-bstr)
  Eval(a.p-bstr,*b.VARIANT)
  ExecuteStatement(a.p-bstr)
  Run(strCommand.p-bstr, intWindowStyle.l, bWaitOnReturn.l)
EndInterface

; Init- and Endfunction
Procedure ScriptControl_Init()
  Global ScriptControl.IScriptControl
  CoInitialize_(0)
  If CoCreateInstance_(?CLSID_ScriptControl, 0, 1, ?IID_IScriptControl, @ScriptControl) = #S_OK
    ScriptControl\Reset()
    ScriptControl\put_Language("VBScript")
  EndIf
  DataSection
  CLSID_ScriptControl:
  Data.l $0E59F1D5
  Data.w $1FBE,$11D0
  Data.b $8F,$F2,$00,$A0,$D1,$00,$38,$BC

  IID_IScriptControl:
  Data.l $0E59F1D3
  Data.w $1FBE,$11D0
  Data.b $8F,$F2,$00,$A0,$D1,$00,$38,$BC
  EndDataSection
EndProcedure

Procedure ScriptControl_End()
  ScriptControl\Release()
  CoUninitialize_()
EndProcedure

Procedure SCtr_About()
  ScriptControl\_AboutBox()
EndProcedure

Procedure SCtr_AddCode(Script.s)
  ProcedureReturn ScriptControl\AddCode(Script)
EndProcedure

Procedure.d SCtr_EvalNum(StringVar.s)
  Protected var.VARIANT
  ScriptControl\Eval(StringVar, @var)
  If var\boolVal
    ProcedureReturn #True
  EndIf
  ProcedureReturn var\dblVal
EndProcedure

Procedure.s SCtr_EvalStr(StringVar.s)
  Protected var.VARIANT
  ScriptControl\Eval(StringVar, @var)
  If var\bstrVal
    ProcedureReturn PeekS(var\bstrVal, #PB_Any, #PB_Unicode)
  EndIf
  ProcedureReturn ""
EndProcedure

Procedure.s SCtr_EvalStr_UNICODE(StringVar.s)
  Protected var.VARIANT, Result.s, Result2.s
  ScriptControl\Eval(StringVar, @var)
  If var\bstrVal
    Result = PeekS(var\bstrVal, #PB_Any, #PB_Unicode)
    If Result
      Result2 = Space(Len(Result)* 2)
      PokeS(@Result2, Result, #PB_Any, #PB_Unicode)
    EndIf
  EndIf
  ProcedureReturn Result2
EndProcedure

Procedure SCtr_Reset()
  ProcedureReturn ScriptControl\Reset()
EndProcedure

Procedure SCtr_Run(Script.s)
  ProcedureReturn ScriptControl\ExecuteStatement(Script)
EndProcedure

Procedure SCtr_SetLanguage(Language.s)
  ProcedureReturn ScriptControl\put_Language(Language)
EndProcedure

Procedure SCtr_SetTimeOut(ms.l)
  ProcedureReturn ScriptControl\put_Timeout(ms)
EndProcedure

Procedure SCtr_GetTimeOut()
  Protected timeout.l
  ScriptControl\get_Timeout(@timeout)
  ProcedureReturn timeout
EndProcedure

Re: VBScript to PureBasic program code generator

Posted: Sun Mar 29, 2015 10:23 am
by Ferdinand
added some lines to deal with WScript object (edited first post)

Re: VBScript to PureBasic program code generator

Posted: Sat Apr 11, 2015 9:42 am
by Ferdinand
As an addition, here are some examples of using VBScript through the ScriptControl in PureBasic:

example 1) as VBScript is (was) used a lot by system administrators, you will see a lot of scripts using the WMI (Windows Management Instrumentation) object; this example is a script (srvinv.vbs) I copied from http://www.robvanderwoude.com/wshexamples.php and transmorgified with the PureBasic program you see in the first post of this thread (some unnecessary lines deleted in the resulting program); the resulting program shows some lines with system information:

Code: Select all

IncludePath "..\..\RESOURCES\IncludeFiles\"
IncludeFile "ScriptControl.pbi"

Procedure.s DoTheScript()
  Protected code$

  code$ + "On Error Resume Next" + #CRLF$
  code$ + "Const wbemFlagReturnImmediately = &h10" + #CRLF$
  code$ + "Const wbemFlagForwardOnly       = &h20" + #CRLF$
  code$ + "Const ForReading                = 1" + #CRLF$
  code$ + "Const ForWriting                = 2" + #CRLF$
  code$ + "Const ForAppending              = 8" + #CRLF$
  code$ + "Set objWMIService = GetObject( "+Chr(34)+"winmgmts://./root/cimv2"+Chr(34)+" )" + #CRLF$
  code$ + "Set colItems = objWMIService.ExecQuery( "+Chr(34)+"Select * from Win32_ComputerSystem"+Chr(34)+", , 48 )" + #CRLF$
  code$ + "For Each objItem in colItems" + #CRLF$
  code$ + " 	strComputer = objItem.Name" + #CRLF$
  code$ + "Next" + #CRLF$
  code$ + "strMsg = vbCrLf & "+Chr(34)+"Computer name  : "+Chr(34)+" & strComputer & vbCrLf" + #CRLF$
  code$ + "Set objWMIService = GetObject( "+Chr(34)+"winmgmts://"+Chr(34)+" & strComputer & "+Chr(34)+"/root/CIMV2"+Chr(34)+" )" + #CRLF$
  code$ + "Set colItems = objWMIService.ExecQuery( "+Chr(34)+"SELECT * FROM Win32_Processor"+Chr(34)+", "+Chr(34)+"WQL"+Chr(34)+", wbemFlagReturnImmediately + wbemFlagForwardOnly )" + #CRLF$
  code$ + "For Each objItem In colItems" + #CRLF$
  code$ + "	strCPUType = Strip( objItem.Name )" + #CRLF$
  code$ + "Next" + #CRLF$
  code$ + "Set colItems = objWMIService.ExecQuery( "+Chr(34)+"SELECT * FROM Win32_ComputerSystem"+Chr(34)+", "+Chr(34)+"WQL"+Chr(34)+", wbemFlagReturnImmediately + wbemFlagForwardOnly )" + #CRLF$
  code$ + "For Each objItem In colItems" + #CRLF$
  code$ + "	If objItem.Domain <> "+Chr(34)+""+Chr(34)+" Then" + #CRLF$
  code$ + "		strMsg = strMsg & "+Chr(34)+"Domain         : "+Chr(34)+" & objItem.Domain     & vbCrLf" + #CRLF$
  code$ + "	Else" + #CRLF$
  code$ + "		strMsg = strMsg & "+Chr(34)+"Domain         : "+Chr(34)+" & objItem.Workgroup  & vbCrLf" + #CRLF$
  code$ + "	End If" + #CRLF$
  code$ + "	strMsg = strMsg & "+Chr(34)+"Manufacturer   : "+Chr(34)+" & objItem.Manufacturer       & vbCrLf" + #CRLF$
  code$ + "	strMsg = strMsg & "+Chr(34)+"Model          : "+Chr(34)+" & objItem.Model              & vbCrLf" + #CRLF$
  code$ + "	strMsg = strMsg & "+Chr(34)+"Processors     : "+Chr(34)+" & objItem.NumberOfProcessors & vbCrLf" + #CRLF$
  code$ + "	strMsg = strMsg & "+Chr(34)+"Processor type : "+Chr(34)+" & strCPUType                 & vbCrLf" + #CRLF$
  code$ + "	strRoles = "+Chr(34)+""+Chr(34) + #CRLF$
  code$ + "	For Each strItem in objItem.Roles" + #CRLF$
  code$ + "		strTemp = strItem" + #CRLF$
  code$ + "		For Each strTest in "+Chr(34)+"LM_Workstation,LM_Server,NT,Server_NT,Backup_Browser,Potential_Browser,"+Chr(34) + #CRLF$
  code$ + "			If strItem = strTest Then" + #CRLF$
  code$ + "				strTemp = "+Chr(34)+""+Chr(34) + #CRLF$
  code$ + "			End If" + #CRLF$
  code$ + "		Next" + #CRLF$
  code$ + "		If strTemp <> "+Chr(34)+""+Chr(34)+" Then" + #CRLF$
  code$ + "			If strRoles = "+Chr(34)+""+Chr(34)+" Then" + #CRLF$
  code$ + "				strRoles = strRoles & "+Chr(34)+", "+Chr(34)+" & strTemp" + #CRLF$
  code$ + "			Else" + #CRLF$
  code$ + "				strRoles = strTemp" + #CRLF$
  code$ + "			End If" + #CRLF$
  code$ + "		End If" + #CRLF$
  code$ + "	Next" + #CRLF$
  code$ + "	strMsg = strMsg & "+Chr(34)+"Roles          : "+Chr(34)+" & strRoles                   & vbCrLf" + #CRLF$
  code$ + "	strMemory = Int( ( objItem.TotalPhysicalMemory / 1048576 ) + 0.5 )" + #CRLF$
  code$ + "	strMsg = strMsg & "+Chr(34)+"Memory         : "+Chr(34)+" & strMemory         & "+Chr(34)+" MB"+Chr(34)+"  & vbCrLf" + #CRLF$
  code$ + "Next" + #CRLF$
  code$ + "Set colItems = objWMIService.ExecQuery( "+Chr(34)+"SELECT * FROM Win32_OperatingSystem"+Chr(34)+", "+Chr(34)+"WQL"+Chr(34)+", wbemFlagReturnImmediately + wbemFlagForwardOnly )" + #CRLF$
  code$ + "For Each objItem In colItems" + #CRLF$
  code$ + "	strMsg = strMsg & "+Chr(34)+"OS Version     : "+Chr(34)+" & objItem.Caption                 & vbCrLf" + #CRLF$
  code$ + "	strMsg = strMsg & "+Chr(34)+"SP Version     : "+Chr(34)+" & objItem.ServicePackMajorVersion & "+Chr(34)+"."+Chr(34)+" & objItem.ServicePackMinorVersion & vbCrLf" + #CRLF$
  code$ + "	strMsg = strMsg & "+Chr(34)+"Serial Number  : "+Chr(34)+" & objItem.SerialNumber            & vbCrLf" + #CRLF$
  code$ + "Next" + #CRLF$
  code$ + "strIPAddress = "+Chr(34)+""+Chr(34) + #CRLF$
  code$ + "strPrevious  = "+Chr(34)+""+Chr(34) + #CRLF$
  code$ + "strMsgIP     = "+Chr(34)+""+Chr(34) + #CRLF$
  code$ + "Set colItems = objWMIService.ExecQuery( "+Chr(34)+"SELECT * FROM Win32_NetworkAdapterConfiguration"+Chr(34)+", "+Chr(34)+"WQL"+Chr(34)+", wbemFlagReturnImmediately + wbemFlagForwardOnly )" + #CRLF$
  code$ + "For Each objItem In colItems" + #CRLF$
  code$ + "	strIPAddress = Join( objItem.IPAddress, "+Chr(34)+","+Chr(34)+" )" + #CRLF$
  code$ + "	If strIPAddress <> strPrevious Then" + #CRLF$
  code$ + "		If strMsgIP = "+Chr(34)+""+Chr(34)+" Then" + #CRLF$
  code$ + "			strMsgIP = "+Chr(34)+"IP Address     : "+Chr(34)+" & strIPAddress" + #CRLF$
  code$ + "		Else" + #CRLF$
  code$ + "			strMsgIP = "+Chr(34)+"IP Addresses   : "+Chr(34)+" & strMsgIP" + #CRLF$
  code$ + "		End If" + #CRLF$
  code$ + "		strPrevious = strIPAddress" + #CRLF$
  code$ + "	End If" + #CRLF$
  code$ + "Next" + #CRLF$
  code$ + "strMsg = strMsg & strMsgIP & vbCrLf" + #CRLF$
  code$ + "Set colItems = objWMIService.ExecQuery( "+Chr(34)+"SELECT * FROM Win32_LogicalDisk WHERE MediaType = 12"+Chr(34)+", "+Chr(34)+"WQL"+Chr(34)+", wbemFlagReturnImmediately + wbemFlagForwardOnly )" + #CRLF$
  code$ + "strMsgDisk = "+Chr(34)+""+Chr(34) + #CRLF$
  code$ + "For Each objItem In colItems" + #CRLF$
  code$ + "	strDisk = objItem.DeviceID & "+Chr(34)+" "+Chr(34)+" & Int( ( objItem.Size / 1073741824 ) + 0.5 )" + #CRLF$
  code$ + "	strFree = objItem.DeviceID & "+Chr(34)+" "+Chr(34)+" & Int( ( 100 * objItem.FreeSpace / objItem.Size ) + 0.5 )" + #CRLF$
  code$ + "	If strMsgDisk = "+Chr(34)+""+Chr(34)+" Then" + #CRLF$
  code$ + "		strMsgDisk = strDisk & "+Chr(34)+" GB"+Chr(34) + #CRLF$
  code$ + "		strMsgFree = strFree & "+Chr(34)+" %"+Chr(34) + #CRLF$
  code$ + "	Else" + #CRLF$
  code$ + "		strMsgDisk = strMsgDisk & "+Chr(34)+", "+Chr(34)+" & strDisk & "+Chr(34)+" GB"+Chr(34) + #CRLF$
  code$ + "		strMsgFree = strMsgFree & "+Chr(34)+", "+Chr(34)+" & strFree & "+Chr(34)+" %"+Chr(34) + #CRLF$
  code$ + "	End If" + #CRLF$
  code$ + "Next" + #CRLF$
  code$ + "strMsg = strMsg & "+Chr(34)+"Logical Drives : "+Chr(34)+" & strMsgDisk & vbCrLf" + #CRLF$
  code$ + "strMsg = strMsg & "+Chr(34)+"Free Space     : "+Chr(34)+" & strMsgFree & vbCrLf" + #CRLF$
  code$ + "Sub ShowError( )" + #CRLF$
  code$ + "	strMsg = vbCrLf & "+Chr(34)+"Reference # "+Chr(34)+" & strRef & vbCrLf & "+Chr(34)+"Error # "+Chr(34)+" _" + #CRLF$
  code$ + "	       & Err.Number & vbCrLf & Err.Description & vbCrLf & vbCrLf" + #CRLF$
  code$ + "	Syntax" + #CRLF$
  code$ + "End Sub" + #CRLF$
  code$ + "Private Function Strip( strInput )" + #CRLF$
  code$ + "	Do While Left( strInput, 1 ) = "+Chr(34)+" "+Chr(34) + #CRLF$
  code$ + "		strInput = Mid( strInput, 2 )" + #CRLF$
  code$ + "	Loop" + #CRLF$
  code$ + "	Strip = strInput" + #CRLF$
  code$ + "End Function" + #CRLF$

  ScriptControl_Init()
  SCtr_Reset()
  SCtr_SetLanguage("VBScript")
  SCtr_AddCode(code$)
  ReturnValue.s=SCtr_EvalStr("strMsg")
  ScriptControl_End()

  ProcedureReturn ReturnValue
EndProcedure

Debug DoTheScript()

End
example 2) checking a date; in PureBasic you can check a date with ParseDate, but ParseDate can only check dates from 1970 onward. What to do if you want to check dates from before 1970 ? In the course of time several solutions have been put forward on this forum for the problem; to solve it using VBScript's IsDate function could look something like this:

Code: Select all

IncludePath "..\..\RESOURCES\IncludeFiles\"

IncludeFile "ScriptControl.pbi"

Procedure IsDate(DateToCheck.s)
  Protected code$
  ScriptControl_Init()
  SCtr_Reset()
  SCtr_SetLanguage("VBScript")
  code$ = "vbsDateOK=IsDate(" + Chr(34) + DateToCheck + Chr(34) + ")" + #CRLF$
  SCtr_AddCode(code$)
  ProcedureReturn SCtr_EvalNum("vbsDateOK")
  ScriptControl_End()
EndProcedure

If IsDate("1900-02-28"): Debug "Date ok": Else: Debug "Date not ok": EndIf
End
example 3) using an Excel function; you need to have Excel installed for this; as an example this little program that calculates the monthly payment for a standard annuity mortgage where parameters: yearly interest rate, total amount of months for payment, total mortgage amount, are passed on to the VBScript code, that uses Excel's PMT function:

Code: Select all

IncludePath "..\..\..\RESOURCES\IncludeFiles\"
IncludeFile "ScriptControl.pbi"

Procedure.s Excel_PMT(YearlyInterest.s, TotalMonths.s, TotalSum.s)
  Protected code$
  
  MonthlyInterest.s = StrF(ValF(YearlyInterest)/12/100,6)
  code$ + "Set objExcel = CreateObject("+Chr(34)+"Excel.Application"+Chr(34)+")" + #CRLF$
  code$ + "objExcel.DisplayAlerts = False" + #CRLF$
  code$ + "objExcel.Visible = False" + #CRLF$
  code$ + "set wb=objExcel.Workbooks.Add" + #CRLF$
  code$ + "objExcel.Cells(1, 1).Value = " + Chr(34) + "=PMT(" + MonthlyInterest+","+TotalMonths+","+TotalSum+")"+Chr(34) + #CRLF$
  code$ + "strMsg =  CStr(-(objExcel.Cells(1, 1).Value))" + #CRLF$
  code$ + "objExcel.Quit" + #CRLF$

  ScriptControl_Init()
  SCtr_Reset()
  SCtr_SetLanguage("VBScript")
  SCtr_AddCode(code$)
  ReturnValue.s=ReplaceString(SCtr_EvalStr("strMsg"),",",".")
  ScriptControl_End()

  ProcedureReturn ReturnValue
EndProcedure

Debug StrF(ValF(Excel_PMT("6", "60", "100000")),2)

End

Re: VBScript to PureBasic program code generator

Posted: Sat Apr 11, 2015 3:22 pm
by rob6523
Very nice!
Thank you for sharing!

Re: VBScript to PureBasic program code generator

Posted: Fri Jun 19, 2015 3:44 pm
by OldSkoolGamer
Nice indeed!
Thanks a TON for sharing this.

Re: VBScript to PureBasic program code generator

Posted: Tue Jul 14, 2015 1:10 am
by Amor_2001
Hello,
Thanks for the code. Excellent.

I have a question. My VBScript provides many values are in different variables. These I would then evaluate in PureBasic. How can I read the contents of the variable in PureBasic.

Many Thanks.

Re: VBScript to PureBasic program code generator

Posted: Tue Jan 23, 2018 4:25 pm
by Kwai chang caine
2015 .. :oops:
Never to late for congratulations :shock:
Thanks a lot for sharing this piece of happiness 8)

Re: VBScript to PureBasic program code generator

Posted: Tue Jan 23, 2018 8:11 pm
by skywalk
I could not get examples to run on Windows 10 x64.
Presumably, the CLSID needs to be updated?
Has anyone done that?