Author Topic: CreateObject in vbscript  (Read 11701 times)

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
CreateObject in vbscript
« on: November 06, 2014, 10:26:58 pm »
Hi,

Is there a limitation on the use of CreateObject in a vbscript within Sparx to create an active x component ?

I'm using:

    Set objIE = CreateObject("InternetExplorer.Application")

And get the error active x component can't be created ??


Regards,

Jon.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: CreateObject in vbscript
« Reply #1 on: November 06, 2014, 10:46:05 pm »
Out of curiosity I tried that and I had no err. Printed objIE and it resulted in "Microsoft Internet Explorer"

q.

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: CreateObject in vbscript
« Reply #2 on: November 06, 2014, 11:05:55 pm »
balls :-)...probably another 'feature' of my companies Windows build !

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: CreateObject in vbscript
« Reply #3 on: November 07, 2014, 12:36:49 am »
Hi

During my testing of scripting within EA there seems to be no limitations that I found put in place by EA.

I've had some fun exploring scripts recently (with no purpose other than to check out what you can do) and found out a lot about what you can do with VBScripts; much more powerful than I thought  - if you are interested some of my findings outlined in my lastest post http://exploringea.com/2014/10/28/customising-ea-a-2nd-look-at-scripting/

Adrian
EXploringEA - information, utilities and addins

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: CreateObject in vbscript
« Reply #4 on: November 08, 2014, 02:06:02 am »
Great blog...See code below - which gave rise to my question ... what I need is a drop down list via vbscript in Sparx (company packaging policy makes it v difficult to distribute an Add-in)...this kind of works - but the IE browser doesn't pop up - just flashes on Windows Taskbar...

Anyone else got any other thoughts about how i could get a dropdown list via vbscript ?


option explicit

!INC Local Scripts.EAConstants-VBScript

Function GetUserInput(myPrompt)
' This function uses Internet Explorer to
' create a dialog and prompt for user input.
'
'
' Argument:   [string] prompt text, e.g. "Please enter your name:"
' Returns:    [string] the user input typed in the dialog screen
'

    Dim objIE

    ' Create an IE object
    Set objIE = CreateObject("InternetExplorer.Application")

    ' Specify some of the IE window's settings
    objIE.Navigate "about:blank"
    objIE.Document.Title = "Input required " & String(100, ".")
    objIE.ToolBar = False
    objIE.Resizable = False
    objIE.StatusBar = False
    objIE.Width = 320
    objIE.Height = 280

    ' Center the dialog window on the screen
    With objIE.Document.ParentWindow.Screen
        objIE.Left = (.AvailWidth - objIE.Width) \ 2
        objIE.Top = (.Availheight - objIE.Height) \ 2
    End With

    ' Wait till IE is ready
    Do While objIE.Busy
'        WScript.Sleep 200
    Loop
    ' Insert the HTML code to prompt for user input
    objIE.Document.Body.InnerHTML = "<div align=""center""><p>" & myPrompt _
                                  & "</p>" & vbCrLf _
                                  & "<p><input type=""text"" size=""20"" " _
                                  & "id=""UserInput""></p>" & vbCrLf _
                                  & "<p><input type=""hidden"" id=""OK"" " _
                                  & "name=""OK"" value=""0"">" _
                                  & "<input type=""submit"" value="" OK "" " _
                                  & "OnClick=""VBScript:OK.Value=1""></p></div>" _
                                  & "<form action="""">" _
                                  & "<select name=""NCA"">" _
                                  & "<option value=""N"">Option 1</option>" _
                                  & "<option value=""C"">Option 2</option>" _
                                  & "<option value=""A"">Option 3 and final!</option>" _
                                  & "</select>" _
                                  & "</form>"


    ' Hide the scrollbars
    objIE.Document.Body.Style.overflow = "auto"
    ' Make the window visible
    objIE.Visible = True
    ' Set focus on input field
    objIE.Document.All.UserInput.Focus

    ' Wait till the OK button has been clicked
    On Error Resume Next
    Do While objIE.Document.All.OK.value = 0
 '       WScript.Sleep 200
        
        If Err Then ' user clicked red X (or alt-F4) to close IE window
            IELogin = Array("", "")
            objIE.Quit
            Set objIE = Nothing
            Exit Function
        End If
    Loop
    On Error GoTo 0


    ' Read the user input from the dialog window
    GetUserInput = objIE.Document.All.UserInput.value & "|" & objIE.Document.All.NCA.value
    ' Close and release the object
    objIE.Quit
    Set objIE = Nothing

End Function

strInput = GetUserInput("Please enter loan number:")
strUserInput = Split(strInput, "|")(0)
strUserDropDown = Split(strInput, "|")(1)

Dim fso, fil, fileso

If Len(strUserInput) > 9 Then
   Set fso = CreateObject("Scripting.FileSystemObject")
   fso.CreateTextFile ("C:\" & strUserInput & ".txt")
   Set fil = fso.GetFile("C:\" & strUserInput & ".txt")
   Set txtfile = fso.CreateTextFile(("C:\" & strUserInput & ".txt"), True)
       txtfile.Write strUserInput
       txtfile.Close

   ReportInfo "Complete!"

Else
   ReportInfo "Invalid Loan Amount!"
End If
« Last Edit: November 08, 2014, 02:06:40 am by openit »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: CreateObject in vbscript
« Reply #5 on: November 08, 2014, 02:25:25 am »
My installation (even with the new beta) opens IE and shows the dialog. Though I can not do much except typing some values. Ok just does nothing.

q.

P.S. and it made the CPU go up to 100%
« Last Edit: November 08, 2014, 02:28:44 am by qwerty »

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: CreateObject in vbscript
« Reply #6 on: November 10, 2014, 12:30:47 am »
I was very curious about how to resolve your problem, not least because the thought of starting up IE to provide a dialog just didn't seem to make sense to me. So did some exploring and found a couple of scripting libraries that provide some simple, and neater looking, solutions.

The libraries I've checked out so far are:

* QuickPrompts (139Kb) - http://www.toptensoftware.com/quickprompts/
* WSO (1.5Mb) - http://www.veretennikov.org/WSO/Help/html_en/index.html

Both much smaller than IE!  However, you will need to register the DLL and not sure if that is an issue in your environment.

I did a quick check and both provide a useful set of windows control including the dropdown list you require.

Here is a simple script that presents a dialog with a combobox and then displays the selected value.

Code: [Select]
 '-Variables-----------------------------------------------------------
    Dim Form
 
 ' create a form using QuickPrompts
    Set Form = CreateObject("QuickPrompts.Form.2")
    If IsObject(Form) Then ' check it was created
      
 ' Example Combobox
      form.CreateControl "ComboBox", "cmbColor", "&Enter Color:", "Red"
      form.cmbColor.HasTextBox = True  
      form.cmbColor.AddItem "Red"
      form.cmbColor.AddItem "Green"
      form.cmbColor.AddItem "Blue"
      form.cmbColor.Value = "Red"

      '-Display the dialog, quit if user cancels------------------------
        Do
        Loop Until Form.DoModal()
 
      '-Display result--------------------------------------------------
        MsgBox " Combo selection = " & form.cmbColor.value
    End If


I need to explore more so I'll probably add a blog post with some more example code on these in due course as I'm really amazed by how make you can do with scripting. Perhaps it was my use of scripts in the early days (1970's) that set my low level of expectation  ::)
« Last Edit: November 10, 2014, 01:40:45 am by MrWappy »
EXploringEA - information, utilities and addins

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: CreateObject in vbscript
« Reply #7 on: November 10, 2014, 05:23:19 am »
I once used QT with Perl but got strange effects eventually.

q.