Solved

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

Posted on 2009-05-20
9
1,509 Views
Last Modified: 2012-05-07
Greetings,

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.
0
Comment
Question by:aceklub97
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 65

Expert Comment

by:RobSampson
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.

Regards,

Rob.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:aceklub97
ID: 24438189
Rob,

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
VBSCode.vbs.txt
HTACode.hta.txt
0
 
LVL 65

Expert Comment

by:RobSampson
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.

Regards,

Rob.
<HTML>
<HEAD>
  <TITLE>
    Nationwide Services Company - Training Room Data Migration Tool
  </TITLE>
  <link href="\\10.120.28.74\scripts\Backup\nwlogo.ico" type="text/css" rel="stylesheet">
  <HTA:application scroll=no>
  <STYLE>
    div.clsIndent {margin-left: 30px}
    div.clsIndentRed {margin-left: 30px; color: red}
  </STYLE>
  <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 \\10.120.28.74\scripts\Backup\nss_Backup.vbs")
		'If Err.number <> 0 Then
		'  lblStatus.innerText = "Failed to start!"
		'Else
      	
 
		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
            window.Close
      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"
          Else
            .className = "clsIndentRed"
          End If
        Else
          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")
      Populate_LOB
    End Sub
 
    Sub window_onunload()
      Set wshShell = Nothing
    End Sub
	
	Sub Populate_LOB
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		strLOBFolder = "\\10.120.28.74\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
		Next
		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 = "\\10.120.28.74\training\"
		ElseIf strBackupStartFolder = "Commercial Lines Processing Center" Then
			strParentFolder = "\\10.120.28.74\Training_CLPC\"
		ElseIf strBackupStartFolder = "Commercial Lines Service Center" Then
			strParentFolder = "\\10.120.28.74\Training_CSC\"					
		ElseIf strBackupStartFolder = "PLSC_Customer Service Unit" Then
			strParentFolder = "\\10.120.28.74\Training_CSU\"
		ElseIf strBackupStartFolder = "PLSC_Exclusive Channel" Then
			strParentFolder = "\\10.120.28.74\Training_PLSCEC\"
		ElseIf strBackupStartFolder = "PLSC_Independent Channel" Then
			strParentFolder = "\\10.120.28.74\Training_PLSCIC\"
		ElseIf strBackupStartFolder = "Speciality Products & Boat" Then
			strParentFolder = "\\10.120.28.74\Training_SPECPROD\"
		ElseIf strBackupStartFolder = "Des Moines Claims Call Center" Then
			strParentFolder = "\\10.120.28.74\Training_DMCCC\"
		ElseIf strBackupStartFolder = "Claims_CLASS" Then
			strParentFolder = "\\10.120.28.74\Training_Claims_CLASS\"
		Else
			MsgBox "You did not select a valid LOB."	
			window.Close
			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
			Next
			strHTML = strHTML & "</select>"
			span_trainer.InnerHTML = strHTML
		End If
 
	End Sub
</SCRIPT>
</HEAD>
<BODY bgcolor="white">
    <img src="\\10.120.28.74\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> 
	  </select>
  </span>
  <br>Select your Trainer:
  <span id="span_trainer">
	  <select size="1" name="cbo_trainer">
	  	<option selected value="cbo_select_trainer"> --- Select Trainer --- </option> 
	  </select>
  </span>
  <br><br>
	<input type='radio' name='optBackupOrRestore' value='optBackup' CHECKED> Backup<br>
	<input type='radio' name='optBackupOrRestore' value='optRestore'> Restore<br>
  <br><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>
  <DIV>
    <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="\\10.120.28.74\scripts\Backup\image001.gif" alt="Go"><br><br><br><br>
     <p>
		<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">
		</object>
		</p><br><br>
  </DIV>
</BODY>
</HTML>

Open in new window

0
 

Author Comment

by:aceklub97
ID: 24440474
Rob,

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.
FullVBSCode.vbs.txt
0
 

Author Comment

by:aceklub97
ID: 24447864
Rob,

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("wscript.shell")
Set network = wscript.createobject("wscript.network")
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?

0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 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("wscript.shell")
Set network = wscript.createobject("wscript.network")

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

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....

Regards,

Rob.
0
 

Author Closing Comment

by:aceklub97
ID: 31583624
Rob,
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
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  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

626 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