tags:

views:

2356

answers:

6

I have a third party application that invokes a vsbscript file for certain operations. I would like to put up a user prompt with a choice of options, either a drop down list or checkbox or some such. However, all I can find is the input box option.

I don't think HTAs are an option in my case (unless there is a way to call them from a .vbs file?)

My other thought was some sort of ActiveX control, but I can't locate a built-in one that would be available by default on WindowsXP/Vista.

Anybody have any ideas on how I could accomplish this?

A: 

Try WshShell.Popup. Depending upon your data that may work for you...

Otherwise you could investigate PowerShell.

RedFilter
If I understand WshShell.Popup correctly, that doesn't give me the options to create my own arbitrary list, for example, "Queue1, Queue2, Queue3" etc, so I don't see that it gains me anything different than the regular input box (http://wsh2.uw.hu/ch08b.html)
Nathan
You could use it repeatedly to say, would you like option 1, then would you like option 2, etc. Not ideal, but it IS a scripting language with pretty much no UI.
RedFilter
YOu could always use the Yes No Maybe Cancel buttons and then explain to the user that Yes mean blah, No mean yeah, Cancel means okay....etc. but really this is kind of ugly.
mrTomahawk
+1  A: 

One option is to script Internet Explorer. You can use VBScript to launch IE and load a local HTML file, and attach a VBScript sub to a form's submit button (or any other JavaScript events), which can then close the IE window as part of its execution.

Tmdean
+1  A: 

The simple answer is, you really can't. Tmdean's solution is the only way I can think of either. That said, you can spruce up the input box so it doesn't look horrible. Give this a run, I don't think it's an epic fail:

Dim bullet
Dim response
bullet = Chr(10) & "   " & Chr(149) & " "
Do
    response = InputBox("Please enter the number that corresponds to your selection:" & Chr(10) & bullet & "1.) Apple" & bullet & "2.) Bannana" & bullet & "3.) Pear" & Chr(10), "Select Thing")
    If response = "" Then WScript.Quit  'Detect Cancel
    If IsNumeric(response) Then Exit Do 'Detect value response.
    MsgBox "You must enter a numeric value.", 48, "Invalid Entry"
Loop
MsgBox "The user chose :" & response, 64, "Yay!"
Oorang
A: 

You can launch an HTA from a VBScript.

Set shell = CreateObject("WScript.Shell")
shell.Run "Test.hta"

EDIT

Since you have full control of the VBScript, could you make the 3rd party VBScript simply call your HTA? You could put the UI and whatever processing code inside of the HTA.

aphoria
One thing aphoria forgot to mention is that you need to include the full path of the hta file, and sometimes you need to nun "mshta.exe ____" where ____ is the path to the hta.
mrTomahawk
I would think the problem with this is not starting the hta, but getting values back from the hta.
Tester101
Yes, I would need to be able to get the values back from the hta.
Nathan
Downvoted? Care to explain?
aphoria
Downvoted because the response does not answer the question. If the question was "how do I start an hta from VBScript" I would have upvoted.
Tester101
Well, he did state that he didn't think you could start an HTA from a VBScript. My answer showed that you can. I may not have given him the complete answer he was looking for, but my answer is certainly relevant. I was surprised by the downvote because I usually only downvote answers that are totally inappropriate.
aphoria
+1  A: 
Tester101
A: 

As an example of @TmDean's suggestion, there's this class that I sometimes use which scripts IE (well, it scripted IE6; I haven't tried the more recent incarnations.)

class IEDisplay
    '~ Based on original work by Tony Hinkle, [email protected]

    private TEMPORARY_FOLDER

    private objShell
    private objIE
    private objFSO
    private objFolder
    private strName
    private streamOut
    private objDIV

    private numHeight
    private numWidth
    private numTop
    private numLeft

    private sub Class_Initialize()
 Dim strComputer
 Dim objWMIService
 Dim colItems
 Dim objItem
 Dim arrMonitors( 10, 1 )
 Dim numMonitorCount

 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objIE = CreateObject("InternetExplorer.Application")

 strComputer = "."
 Set objWMIService = GetObject( "winmgmts:\\" & strComputer & "\root\cimv2")
 Set colItems = objWMIService.ExecQuery( "Select  * from Win32_DesktopMonitor")

 numMonitorCount = 0 
 For Each objItem in colItems
     arrMonitors( numMonitorCount, 0 ) = objItem.ScreenHeight
     arrMonitors( numMonitorCount, 1 ) = objItem.ScreenWidth
     numMonitorCount = numMonitorCount + 1
 Next

 numHeight = arrMonitors( 0, 0 )
 numWidth = arrMonitors( 0, 1 )

 Set objFSO = CreateObject("Scripting.FileSystemObject")
 TEMPORARY_FOLDER = 2
 set objFolder = objFSO.GetSpecialFolder( TEMPORARY_FOLDER )
 strName = objFSO.BuildPath( objFolder, objFSO.GetTempName ) & ".html"
 WriteFileU strName, Join( Array( "<HTML><HEAD><TITLE>Information</TITLE></HEAD>", _
      "<BODY SCROLL='NO'><CENTER><FONT FACE='arial black'> <HR COLOR='BLACK'>", _
      "<DIV id='MakeMeAnObject'></DIV>", _
      "<HR COLOR='BLACK'></FONT></CENTER></BODY></HTML>" ), vbCRLF ), WF_CREATE        
 numTop = 0
 numLeft = 0
    end sub

    Sub Init( strPosition )
 'NW, N, NE, W, CENTRE, E, SW, S, SE
 Select Case strPosition
 Case "NW"
     numTop = 0
     numLeft = 0
 Case "N"
     numTop = 0
     numLeft = ( numWidth / 2 ) - 250
 Case "NE"
     numTop = 0
     numLeft = numWidth - 500
 Case "W"
     numTop = ( numHeight / 2 ) - 55
     numLeft = 0
 Case "CENTRE"
     numTop = ( numHeight / 2 ) - 55
     numLeft = ( numWidth / 2 ) - 250
 Case "E"
     numTop = ( numHeight / 2 ) - 55
     numLeft = numWidth - 500
 Case "SW"
     numTop = numHeight - 110
     numLeft = 0
 Case "S"
     numTop = numHeight - 110
     numLeft = ( numWidth / 2 ) - 250
 Case "SE"
     numTop = numHeight - 110
     numLeft = numWidth - 500
 Case Else
     numTop = 0
     numLeft = 0
 End Select

 SetupIE( strName )
 Set objDIV = objIE.Document.All("MakeMeAnObject")
    end sub

    private sub Class_Terminate()
 'Close IE and delete the file
 objIE.Quit
 '~ optionally you may want to get rid of the temp file
    end sub

    public sub Display( strMsg, numMillisec )
 objDIV.InnerHTML = strMsg
 WScript.Sleep numMillisec
    end sub

    Private Sub SetupIE(File2Load)
  objIE.Navigate File2Load
  objIE.ToolBar = False
  objIE.StatusBar = False
  objIE.Resizable = False

  Do
  Loop While objIE.Busy

  objIE.Width = 500
  objIE.Height = 110
  objIE.Left = numLeft
  objIE.Top = numTop
  objIE.Visible = True
  objShell.AppActivate("Microsoft Internet Explorer")
    End Sub

end class

and then as an example of it's use

set i = new IEDisplay 
a = array("NW", "N", "NE", "W", "CENTRE", "E", "SW","S","SE")
for each aa in a
    i.init aa
    i.display "Here in " & aa & " of screen", 1000
next

Now that's not immediately useful (especially are there are a pile of calls to my own utility routines in there) but it gives a framework. By modifying what HTML is stored, you could add support for listboxes etc.

boost