I have been converting a (working) program from PB8 to PB9, involving the MSScript Control. I am not feeling good about the results. The code in the PB COM Browser generated file is quite different from PB8. I have tried to meet the requirements with some code which uses José's ideas. The .Run method does not work, and the whole object seem less than robust. This makes me think I have missed a conversion of a parameter. If anyone could look this over as you have a chance I would be most appreciative. The ScrCntl.Inc is the PB COM Browser generated file.
This program is a cut down version of a larger program, but illustrates the issues.
Thank you so much for looking.
Chuck de Young
This program is a cut down version of a larger program, but illustrates the issues.
Code:
#Compile Exe Option Explicit #Include "C:\PBWin90\WinAPI\Win32API.Inc" #Include "C:\PBWin90\WinAPI\VBAPI32.Inc" #Include "ScrCntl.Inc" ' ' SAFEARRAY API ' Declare Function SafeArrayCreate Lib "oleaut32.DLL" Alias "SafeArrayCreate"(ByVal vt As Word, ByVal cDims As Dword,ByRef rgsabounds As SAFEARRAYBOUND) As Dword Declare Function SafeArrayDestroy Lib "oleaut32.DLL" Alias "SafeArrayDestroy"(ByVal hsa As Dword) As Dword Declare Function SafeArrayPutElement Lib "oleaut32.DLL" Alias "SafeArrayPutElement"(ByVal hsa As Dword,ByRef rgIndices As Long,ByVal pvData As Dword) As Dword Function PBMain () As Long Local sCode As String sCode = "" sCode = sCode & "Option Explicit" & $CrLf sCode = sCode & "" & $CrLf sCode = sCode & "MsgBox ""Hello""" & $CrLf sCode = sCode & "" & $CrLf sCode = sCode & "Sub Main()" & $CrLf sCode = sCode & "MsgBox ""World""" & $CrLf sCode = sCode & "End Sub" & $CrLf ScriptCall "Language.Let", "VBScript" 'MsgBox ScriptCall("Language.Get", "") ScriptCall "AddCode", sCode ScriptCall "Run", "Main" End Function Function ScriptCall(Op As String, AValue As String) As String Dim SC As Static IScriptControl Dim pProcedures As IScriptProcedureCollection Local sK, sWork As String Local VX As Variant Local rgsabound As SAFEARRAYBOUND Local SE As IScriptError Local Params, psa As Dword Local I, RetVal As Long Local lWork, bDebugPsa As Long If IsFalse IsObject(SC) Then Try SC = NewCom $PROGID_MSScriptControl_ScriptControl If IsFalse IsObject(SC) Then MsgBox "SC not an object", %mb_ok, "Instance" End If Catch SE = SC.Error MsgBox Format$(Err) & " " & Error$(ErrClear) & $Lf & " " & Format$(SE.Number) & " " & ACode$(SE.Description), %mb_ok, "Instance" End Try End If Select Case LCase$(Op) Case "timeout.let" SC.Timeout = Val(AValue) Case "timeout.get" Function = Format$(SC.Timeout) Case "language.let" ' Place the passed value into SC as chosen scripting language. SC.Language = UCode$(AValue) Case "language.get" ' Return the current language. Try sWork = SC.Language Function = ACode$(sWork) Catch SE = SC.Error MsgBox Format$(Err) & " " & Error$(ErrClear) & $Lf & " " & Format$(SE.Number) & " " & ACode$(SE.Description), %mb_ok, "Language.Get" End Try Case "addcode" ' Add code to SC, code passed in as AValue. SC.AddCode UCode$(AValue) pProcedures = SC.Procedures 'MsgBox "pProcedures returned" sWork = Format$(pProcedures.Count) 'MsgBox sWork If Val(sWork) > 0 Then sWork = SC.Procedures.Item(1).Name 'MsgBox ACode$(sWork) Else MsgBox sWork End If Case "run" If SC.Procedures.Count = 0 Then MsgBox "No procedures available.", %mb_ok Exit Function End If VX = "" Try bDebugPsa = %True If IsTrue bDebugPsa Then SafeArrayGetElement psa, ByVal VarPtr(I), ByVal VarPtr(VX) lWork = VariantVT(VX) Select Case lWork Case 8, 30, 31 sK = Variant$(VX) sK = "VT " & Format$(lWork) & " " & ACode$(sK) Case Else sK = "VT " & Format$(lWork) & " " & Format$(Variant#(VX)) End Select 'MsgBox sK End If sK = AValue Try sWork = SC.Procedures.Item(1).Name If ACode$(sWork) <> sK Then MsgBox "Procedure name problem" End If MsgBox "Running " & sK sK = UCode$(sK) VX = SC.Run(ByVal sK, ByVal psa) Catch SE = SC.Error MsgBox Format$(Err) & " " & Error$(ErrClear) & $Lf & " " & Format$(SE.Number) & " " & ACode$(SE.Description), %mb_ok, "SC.Run" Finally Function = Variant$(VX) End Try Catch SE = SC.Error MsgBox Format$(Err) & " " & Error$(ErrClear) & $Lf & " " & Format$(SE.Number) & " " & ACode$(SE.Description), %mb_ok, "Run" Finally If psa Then SafeArrayDestroy psa Function = Variant$(VX) End Try Case "evaluate" sK = UCode$(AValue) Try VX = SC.Eval(sK) Select Case VariantVT(VX) Case 8, 30, 31 Function = Variant$(VX) Case Else Function = Format$(Variant#(VX)) End Select Catch SE = SC.Error MsgBox Format$(Err) & " " & Error$(ErrClear) & $Lf & " " & Format$(SE.Number) & " " & ACode$(SE.Description), %mb_ok, "Eval" End Try Case "execute" sK = UCode$(AValue) Try SC.ExecuteStatement sK Catch SE = SC.Error MsgBox Format$(Err) & " " & Error$(ErrClear) & $Lf & " " & Format$(SE.Number) & " " & ACode$(SE.Description), %mb_ok, "Execute" End Try Case "close" Set SC = Nothing End Select End Function
Chuck de Young
Comment