Improve company productivity with a Business Account.Sign Up


VBScript -  Can I convert MSGBox prompts into Radio Buttons or Dropdown Menus?

Posted on 2009-05-20
Medium Priority
Last Modified: 2012-05-07

I have a script that peforms the followings:
1. Pops a messagebox up that displays a list of groups that are found in a folder, and has the customer type a corresponding numnber in the message box.
2.  Depending on the answer, go to the particualr start folder and prompts them for the particular sub group that are found within that group
3.  Once that data is set is asked them whether they want to backup or restore.  And then either creates or accesses a backupfolder that is created from the first two response.

Everything works perfectly, but it is that user friendly.  Is there way that I can have thos prompts converted to either drop-down menus or Radio buttons on the .hta screen that I have calling the .vbs script?  If I were able to have the same functionality and be able to read the information into the script the same way that would be perfect.
Question by:aceklub97
  • 4
  • 3
  • 2
LVL 65

Expert Comment

ID: 24437827
You can embed the script into the HTA, and instead of reading the InputBox values, you just use something like
strGroup = lst_groups.Value

to read which group name has been selected from a list box.

Perhaps if you post the scripts (the HTA and VBS) we could help you combine them.


Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 24438189

1. I have attached to porttion of the code that I need to read the information.  I didn't include the core part of the script because it is just copying files.
2.  I have included the .hta file that I have.  It is realatively simple.  I would like to be able to have the customer select a. There business group, and then b. the name of their trainer, and c.  Whether they want to backup or restore.

If you need any more information, please let me know
LVL 65

Expert Comment

ID: 24438772
OK, I've changed the HTA a bit, to include the drop down and radio boxes, but currently, when you click Start, nothing happens.  You'll need to copy in the code from the VBS that actually does the operation based on the folders and values.  At the moment, you select your options, then click Start, and it just outputs what you've selected.  Once you're happy with that, you can add your code below this line

        'tmrExternal = window.setInterval("tmrExternal_timer", 1000, "VBScript")      

to have it perform additional steps based on the values selected.

I hope this helps so far.


    Nationwide Services Company - Training Room Data Migration Tool
  <link href="\\\scripts\Backup\nwlogo.ico" type="text/css" rel="stylesheet">
  <HTA:application scroll=no>
    div.clsIndent {margin-left: 30px}
    div.clsIndentRed {margin-left: 30px; color: red}
  <SCRIPT language=VBScript>
    Option Explicit
    Const WshRunning = 0
    Const WshFinished = 1
    Dim wshShell
    Dim wseExternal
    Dim tmrExternal
    Dim strComputer
    Dim objWMIService
    Dim colItems
    Dim intHorizontal
    Dim intVertical
    Dim objExplorer
    Dim colServices
    Dim intServices
    Dim intIncrement
	Dim strBackupStartFolder
	Dim strParentFolder
	Dim strHTML
	Dim objFSO
	Dim strLOBFolder
	Dim objSubFolder
	Dim backupOrRestoreResponse
    Sub cmdStart_onclick()
		'On Error Resume Next
		'Set wseExternal = _
		'  wshShell.Exec("Wscript.exe //NOLOGO \\\scripts\Backup\nss_Backup.vbs")
		'If Err.number <> 0 Then
		'  lblStatus.innerText = "Failed to start!"
		If optBackupOrRestore(0).Checked = True Then
			backupOrRestoreResponse = 0
		ElseIf optBackupOrRestore(1).Checked = True Then
			backupOrRestoreResponse = 1
		End If
        lblStatus.innerText = "Your Backup/Restore is in progress.  Please do not use your keyboard or mouse ... This process could take several minutes to complete." & VbCrLf & _
        "LOB: " & cbo_LOB.Value & VbCrLf & _
        "Trainer: " & cbo_Trainer.Value & VbCrLf & _
        "Backup Or Restore: " & backupOrRestoreResponse
        cmdStart.disabled = True
        cmdReset.disabled = True
        buttonClose.disabled = True
        'tmrExternal = window.setInterval("tmrExternal_timer", 1000, "VBScript")             	       
      ' End if
End sub
'sub cmdStart_Progress()
'End sub
    Sub cmdReset_onclick()
      lblStatus.innerText = "Click the Start Button to begin the process:"
      lblResults.innerHTML = " "
      lblMore.innerHTML = ""
      cmdReset.disabled = true
      cmdStart.disabled = False
    End Sub
   'Button Close
		Sub ButtonCloseClick()
      If msgbox ("Are you sure you want to Close?",4,"Close Backup?") = vbYes then
      End if
		End Sub 
    Sub Continue()
      lblMore.innerHTML = _
          "The Data Migration process has completed.<br>" _
        & vbCrLf & "If you have just backed up your PC, please go to your new PC and run this process again, selecting '1' for restore.<P>" _
        & vbCrLf & "If you have just restored you data to the new PC, then your work is done. Please double check to make sure everything was successfully transfered.<br>" _
        & vbCrLf & "If you have any computer related issues, please call the IT Service Desk at 515-508-8515." _
        & VbCrLf & VbCrLf
    cmdReset.disabled = true
    buttonClose.disabled = false
    cmdStart.disabled = False
    End Sub
    Sub tmrExternal_timer()
      With lblStatus
        If wseExternal.Status = WshRunning Then
          If .className = "clsIndentRed" Then
            .className = "clsIndent"
            .className = "clsIndentRed"
          End If
          window.clearInterval tmrExternal
          .innerText = _
              "Finished. Exit code " _
            & CStr(wseExternal.ExitCode)
          .className = "clsIndent"
          Set wseExternal = Nothing
          window.setTimeout "Continue", 200, "VBScript"
        End If
      End With
    End Sub
    Sub window_onload()
      Set wshShell = CreateObject("WScript.Shell")
    End Sub
    Sub window_onunload()
      Set wshShell = Nothing
    End Sub
	Sub Populate_LOB
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		strLOBFolder = "\\\Line_of_Business\"
		If Right(strLOBFolder, 1) = "\" Then strLOBFolder = Left(strLOBFolder, Len(strLOBFolder) - 1)
		strHTML = "<select size='1' name='cbo_lob' onchange='Populate_Trainer'" & VbCrLf
		strHTML = strHTML & "<option selected value='cbo_select_lob'> --- Select Line Of Business --- </option>" & VbCrLf
		For Each objSubFolder In objFSO.GetFolder(strLOBFolder).SubFolders
			strHTML = strHTML & "<option value='" & objSubFolder.Name & "'>" & objSubFolder.Name & "</option>" & VbCrLf
		strHTML = strHTML & "</select>"
		span_lob.InnerHTML = strHTML
   End Sub
	Sub Populate_Trainer
      	Dim boolValid
      	boolValid = True
      	strBackupStartFolder = cbo_lob.Value
		If strBackupStartFolder = "Nationwide Sales Solutions" Then
			strParentFolder = "\\\training\"
		ElseIf strBackupStartFolder = "Commercial Lines Processing Center" Then
			strParentFolder = "\\\Training_CLPC\"
		ElseIf strBackupStartFolder = "Commercial Lines Service Center" Then
			strParentFolder = "\\\Training_CSC\"					
		ElseIf strBackupStartFolder = "PLSC_Customer Service Unit" Then
			strParentFolder = "\\\Training_CSU\"
		ElseIf strBackupStartFolder = "PLSC_Exclusive Channel" Then
			strParentFolder = "\\\Training_PLSCEC\"
		ElseIf strBackupStartFolder = "PLSC_Independent Channel" Then
			strParentFolder = "\\\Training_PLSCIC\"
		ElseIf strBackupStartFolder = "Speciality Products & Boat" Then
			strParentFolder = "\\\Training_SPECPROD\"
		ElseIf strBackupStartFolder = "Des Moines Claims Call Center" Then
			strParentFolder = "\\\Training_DMCCC\"
		ElseIf strBackupStartFolder = "Claims_CLASS" Then
			strParentFolder = "\\\Training_Claims_CLASS\"
			MsgBox "You did not select a valid LOB."	
			boolValid = False
		End If
		If boolValid = True Then
			If Right(strParentFolder, 1) = "\" Then strParentFolder = Left(strParentFolder, Len(strParentFolder) - 1)
			strHTML = "<select size='1' name='cbo_trainer'" & VbCrLf
			strHTML = strHTML & "<option selected value='cbo_select_trainer'> --- Select Trainer --- </option>" & VbCrLf
			For Each objSubFolder In objFSO.GetFolder(strParentFolder).SubFolders
				strHTML = strHTML & "<option value='" & objSubFolder.Name & "'>" & objSubFolder.Name & "</option>" & VbCrLf
			strHTML = strHTML & "</select>"
			span_trainer.InnerHTML = strHTML
		End If
	End Sub
<BODY bgcolor="white">
    <img src="\\\scripts\Backup\image002.gif" alt="Go"><br><br><br><br><br><br>
  <H3>Data Migration Status:</H3>
  <DIV id=lblStatus class=clsIndent>Ready to begin</DIV>
  Select your Line of Business:
  <span id="span_lob">
	  <select size="1" name="cbo_lob">
	  	<option selected value="cbo_select_lob"> --- Select Line of Business --- </option> 
  <br>Select your Trainer:
  <span id="span_trainer">
	  <select size="1" name="cbo_trainer">
	  	<option selected value="cbo_select_trainer"> --- Select Trainer --- </option> 
	<input type='radio' name='optBackupOrRestore' value='optBackup' CHECKED> Backup<br>
	<input type='radio' name='optBackupOrRestore' value='optRestore'> Restore<br>
  <H3><span style="text-decoration:underline">Click the Start Button</span> to begin the process. <br><span style="text-decoration:underline">Click the Close Button</span> when the process has finished:</H3><br>
    <DIV id=lblMore class=clsIndent></DIV><br>
    <INPUT type=button id=cmdStart value="Start"> 
    <INPUT type=button id=cmdReset value=Reset disabled>
    <button accesskey=C id=buttonClose onclick=ButtonCloseClick><U>C</U>lose</button><br><br><br>
    <img src="\\\scripts\Backup\image001.gif" alt="Go"><br><br><br><br>
		<object classid="clsid:35053A22-8589-11D1-B16A-00C0F0283628" id="ProgressBar1" height="20" width="400">
    <param name="Min" value="0">
    <param name="Max" value="100">
    <param name="Orientation" value="0">
    <param name="Scrolling" value="1">

Open in new window


Author Comment

ID: 24440474

Ok.  This make a lot of sense.  I will work on this when I get into the office today.   Just to clarify to make sure that I have what you are saying I have included the full script I have so far.

are you saying:
1. To go down through the rest of the VBscript and tranfer each "function" to a the .hta as a Sub similar to way you currently have Sub Populate_trainer?
2. I am a little confused.  Are we able to transfer all of the code to the .hta and not need the external script anymore?  Or do we still need to call both.

Thanks for the help to so far.  This coming along great.  VBS code attached.

Author Comment

ID: 24447864

I am trying to include the VBSCript into  the .hta.  I am able to get all the const and variables entered in. but when I list the instance, I get a vbscript runtime error.  The orignal VBS works fine, but now when I pasted:

'GLOBAL OBJECT INSTANCES DECLARATIONS ********************************************************************

Set fso     = wscript.createobject("Scripting.FileSystemObject")
Set shell   = wscript.createobject("")
Set network = wscript.createobject("")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTrainers = CreateObject("Scripting.Dictionary")
Set objLOB = CreateObject("Scripting.Dictionary")
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set WshShell = WScript.CreateObject("WScript.Shell")

I get :
An error occured in the script of this page.
Line 80
Char 1
Error Variable is undefined: "wscript"
Code 0

The line in question is, "Set fso     = wscript.createobject("Scripting.FileSystemObject")".   I don't see whats wrong.  fso is already declared as DIM

am I doing something wrong?

LVL 65

Accepted Solution

RobSampson earned 2000 total points
ID: 24447884
Yeah, that's an easy one....the WScript object is not availabe in a HTA, when creating objects in this manner, so all you need to do is change
Set fso     = wscript.createobject("Scripting.FileSystemObject")
Set shell   = wscript.createobject("")
Set network = wscript.createobject("")

Set fso     = createobject("Scripting.FileSystemObject")
Set shell   = createobject("")
Set network = createobject("")

as the CreateObject call works perfectly well without the WScript bit.

I don't have time at the moment to go through your whole script, but if you get stuck, let me know....



Author Closing Comment

ID: 31583624
That worked out great.  Things are so much easier to manage from the .hta as opposed to the MsgBox.  Thanks for all your help.   If I could just figure out how to get a viable progress bar to run on my form, I would be golden.  I have had an open question on that one for a while now.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Watch the working video to know how to import Outlook PST/OST files to Amazon WorkMail. Kernel released this tool which is very easy to use and migrate single or multiple PST and OST files to Amazon WorkMail. To know more about Kernel Import PST to …

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question