Author Topic: IScriptControl.AllowUI Property  (Read 5269 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
IScriptControl.AllowUI Property
« on: July 15, 2008, 12:48:45 AM »

The following code illustrates the use of the AllowUI property.

Code: [Select]
' ########################################################################################
' Microsoft Script Control example.
' 2008 José Roca - Use at your own risk.
' ########################################################################################

' SED_PBWIN  ' Use the PBWIN compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "MSSCRIPT.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pSc AS IScriptControl
   LOCAL strScript AS STRING
   LOCAL vRes AS VARIANT
   LOCAL vPrms AS VARIANT
   LOCAL rgsabound AS SAFEARRAYBOUND
   LOCAL psa AS DWORD
   LOCAL vPrm AS VARIANT
   LOCAL vEmpty AS VARIANT
   LOCAL ix AS LONG

   ' Create an instance of the Microsoft Script Control
   pSc = NEWCOM "MSScriptControl.ScriptControl"
   IF ISNOTHING(pSc) THEN
      MSGBOX "Error creating an instance of the Microsoft Script Control"
      EXIT FUNCTION
   END IF

   TRY
      ' Set the language. It can be "VBScript" or "JScript"
      pSc.Language = UCODE$("VBScript")
      ' Deactivate the user interface
      pSc.AllowUI = %VARIANT_FALSE
      ' Make an script
      strScript = "Sub Main" & $CRLF & _
                  "   MsgBox ""The user interface is activated.""" & $CRLF & _
                  "End Sub"
      pSc.AddCode UCODE$(StrScript)
      ' Create a safearray with zero elements
      ' Note: Parameters are passed as a safearray by reference. Therefore, we
      ' need to always pass a valid pointer.
      rgsabound.lLBound = 1
      rgsabound.cElements = 0
      psa = SafeArrayCreate(%VT_VARIANT, 1, rgsabound)
      ' Run the script
      vRes = pSc.Run(UCODE$("Main"), psa)
   CATCH
      MSGBOX MSScriptControl_GetErrorInfo(pSc, OBJRESULT)
   FINALLY
      ' Destroy the safearray
      IF psa THEN SafeArrayDestroy psa
      psa = %NULL
   END TRY

   ' Releases the interface
   pSc = NOTHING

END FUNCTION
' ========================================================================================
« Last Edit: August 07, 2011, 08:01:46 AM by José Roca »