Solved

Passing variables between pages (hta/vbs)

Posted on 2010-09-22
16
643 Views
Last Modified: 2012-05-10
Hi guys,

Id like to use vbscript (hta) to build the following web pages.

Web page       Action to do on this page
==========================================
Web page 1      Choose Computer type: (laptop or desktop)
Web page 2      Choose Build type: (build or rebuild)
Web page 3      Choose Country: (countries listed in a select box)
Web page 4      Selection Summary: Display options chosen (then confirm y/n to continue)


So, basically, id love some help on how to contruct these web/hta pages so that on web page 4, I would have something like below:

--------------------------------------------------------------- webpage4.hta

You have selected the following options:

Computer type:  desktop (or laptop, depending on what was chosen on web page 1)
Build type: build (or rebuild, depending on what was chosen on web page 2)
Country: Australia (or whatever country selected on web page 3)

Confirmation:
Press the yes button to proceed or the no button to abort.




Any help on this greatly appreciated.

0
Comment
Question by:Simon336697
  • 8
  • 8
16 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 33739775
Hi Simon, this could probably be done all on one page, as you're not presenting that much info each time....what would actually happen when the user clicks "Yes" at the end?  Or do you have that part handled?

Regards,

Rob.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 33762516
Hi Rob,

Hope you are well Rob.
I have that part handled Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33763255
OK sure.  I'll knock up a quick HTA for you tomorrow then.

Rob.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 33765911
Thanks so much Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33766507
OK, here's a quick effort.  You will see when you click Run, it picks up the "value" from the combo boxes.

Regards,

Rob.
<html>

<head>

<title>Request Details</title>

<HTA:APPLICATION 

     APPLICATIONNAME="Request Details"

     BORDER="thin"

     SCROLL="no"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

 

<script language="VBScript">

 

Dim strHTAPath

 

Sub Window_onLoad

	intWidth = 800

	intHeight = 600

	Me.ResizeTo intWidth, intHeight

	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))

	If Mid(document.location, 6, 3) = "///" Then

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)

	Else

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)

	End If

End Sub

 

Sub Run_Program

	MsgBox "Computer Type: " & cboComputerType.Value & VbCrLf & _

		"Build Type: " & cboBuildType.Value & VbCrLf & _

		"Country: " & cboCountry.Value

End Sub

 

</script>

</head>

<body style="background-color:#B0C4DE">

        <table width='90%' height='90%' align='center' border='0'>

                <tr>

                        <td align="center" style="font-family: arial; font-size: 24px; font-weight: bold;">

                                Request Details

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Computer Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboComputerType" id="cboComputerType">

                                	<option id="optComputerType" value="Laptop">Laptop</option>

                                	<option id="optComputerType" value="Desktop">Desktop</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Build Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboBuildType" id="cboBuildType">

                                	<option id="optBuildType" value="Build">Build</option>

                                	<option id="optBuildType" value="Rebuild">Rebuild</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Country: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboCountry" id="cboCountry">

                                	<option id="optCountry" value="Australia">Australia</option>

                                	<option id="optCountry" value="New Zealand">New Zealand</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='center'>

                                <input type="button" value="Run" name="btn_run" onClick="vbs:Run_Program" style="font-size: 16px;"><br><br>

                        </td>

                        <td align='center'>

                                <input type="button" value="Exit" name="btn_exit" onClick="vbs:window.close" style="font-size: 16px;"><br><br>

                        </td>

                </tr>

        </table>

</body>

</html>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 33783977
Hi Rob,
This is great.

Rob, can I ask you.

When you click on the run button, which has code:

<input type="button" value="Run" name="btn_run" onClick="vbs:Run_Program" style="font-size: 16px;"><br><br>

and runs the Run_Program sub as follows:

Sub Run_Program
      MsgBox "Computer Type: " & cboComputerType.Value & VbCrLf & _
            "Build Type: " & cboBuildType.Value & VbCrLf & _
            "Country: " & cboCountry.Value
End Sub


This has on button, an ok button.

Is there a way to:
1.Add a second button for cancel, so that if the user presses this, it resets the 3 select boxes on the page?
2.If they click on OK, it fires off a batch file that launches notepad?

Thanks so much for your help.

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33784240
Sure, try this.

Regards,

Rob.
<html>

<head>

<title>Request Details</title>

<HTA:APPLICATION 

     APPLICATIONNAME="Request Details"

     BORDER="thin"

     SCROLL="no"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

 

<script language="VBScript">

 

Dim strHTAPath

 

Sub Window_onLoad

	intWidth = 800

	intHeight = 600

	Me.ResizeTo intWidth, intHeight

	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))

	If Mid(document.location, 6, 3) = "///" Then

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)

	Else

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)

	End If

End Sub

 

Sub Run_Program

	If cboComputerType.Value = "NONE" Then

		MsgBox "Please select a computer type."

		cboComputerType.Focus

	ElseIf cboBuildType.Value = "NONE" Then

		MsgBox "Please select a build type."

		cboBuildType.Focus

	ElseIf cboCountry.Value = "NONE" Then

		MsgBox "Please select a country."

		cboCounty.Focus

	Else

		intReturn = MsgBox("Selected Options:" & VbCrLf & "Computer Type: " & cboComputerType.Value & VbCrLf & _

			"Build Type: " & cboBuildType.Value & VbCrLf & _

			"Country: " & cboCountry.Value & VbCrLf & VbCrLf & _

			"Do you want to continue?", vbYesNo, "Confirmation")

		If intReturn = vbYes Then

			MsgBox "Running"

		Else

			cboComputerType.Value = "NONE"

			cboBuildType.Value = "NONE"

			cboCountry.Value = "NONE"

			MsgBox "You cancelled the operation."

		End If

	End If

End Sub

 

</script>

</head>

<body style="background-color:#B0C4DE">

        <table width='90%' height='90%' align='center' border='0'>

                <tr>

                        <td align="center" style="font-family: arial; font-size: 24px; font-weight: bold;">

                                Request Details

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Computer Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboComputerType" id="cboComputerType">

                                	<option id="optComputerType" value="NONE"> --- Select --- </option>

                                	<option id="optComputerType" value="Laptop">Laptop</option>

                                	<option id="optComputerType" value="Desktop">Desktop</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Build Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboBuildType" id="cboBuildType">

                                	<option id="optBuildType" value="NONE"> --- Select --- </option>

                                	<option id="optBuildType" value="Build">Build</option>

                                	<option id="optBuildType" value="Rebuild">Rebuild</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Country: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboCountry" id="cboCountry">

                                	<option id="optCountry" value="NONE"> --- Select --- </option>

                                	<option id="optCountry" value="Australia">Australia</option>

                                	<option id="optCountry" value="New Zealand">New Zealand</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='center'>

                                <input type="button" value="Run" name="btn_run" onClick="vbs:Run_Program" style="font-size: 16px;"><br><br>

                        </td>

                        <td align='center'>

                                <input type="button" value="Exit" name="btn_exit" onClick="vbs:window.close" style="font-size: 16px;"><br><br>

                        </td>

                </tr>

        </table>

</body>

</html>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 33787468
Hi Rob,

thanks so much again.

Rob,

If I paste all your code in a file called 'test.hta', I get the following message if I fail to select an entry for the Country select box.
Line: 37
Error: Object required: 'cboCounty'
This does not happen if I deliberatly test not selecting an entry for the other 2 select boxes.

The funny thing is, is that if I paste all your code in a file called 'test.html', I dont get any error messages like those above.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:Simon336697
ID: 33787484
Rob please disregard my last question. Found the problem.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33787498
Oh sorry....this line
            cboCounty.Focus

should have been
            cboCountry.Focus

Forgot the "r"....

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33787500
Hmmm, it's lucky I didn't forget a different letter ;-)
0
 
LVL 1

Author Comment

by:Simon336697
ID: 33787555
Rob,

Is there a way for example, removing the following lines:

                                <select size="1" name="cboCountry" id="cboCountry">
                                      <option id="optCountry" value="NONE"> --- Select --- </option>
                                      <option id="optCountry" value="Australia">Australia</option>
                                      <option id="optCountry" value="New Zealand">New Zealand</option>
                                </select>

and get the hta to read a text file called 'countries.txt' to load the combo box options?
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 33794361
Yep, sure.  This will read from a file called Countries.txt in the same folder as the HTA file.

Regards,

Rob.
<html>

<head>

<title>Request Details</title>

<HTA:APPLICATION 

     APPLICATIONNAME="Request Details"

     BORDER="thin"

     SCROLL="no"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

 

<script language="VBScript">

 

Dim strHTAPath

 

Sub Window_onLoad

	intWidth = 800

	intHeight = 600

	Me.ResizeTo intWidth, intHeight

	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))

	If Mid(document.location, 6, 3) = "///" Then

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)

	Else

		strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)

	End If

	Populate_Countries

End Sub

 

Sub Populate_Countries

	Set objFSO = CreateObject("Scripting.FileSystemObject")

	Const intForReading = 1

	strCountriesFile = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "Countries.txt"

	Set objCountries = objFSO.OpenTextFile(strCountriesFile, intForReading, False)

	While Not objCountries.AtEndOfStream

		strCountry = Trim(objCountries.ReadLine)

		If strCountry <> "" Then

			Set objOption = Document.CreateElement("OPTION")

			objOption.Text = strCountry

			objOption.Value = strCountry

			cboCountry.Add(objOption)

		End If

	Wend

	objCountries.Close

End Sub



Sub Run_Program

	If cboComputerType.Value = "NONE" Then

		MsgBox "Please select a computer type."

		cboComputerType.Focus

	ElseIf cboBuildType.Value = "NONE" Then

		MsgBox "Please select a build type."

		cboBuildType.Focus

	ElseIf cboCountry.Value = "NONE" Then

		MsgBox "Please select a country."

		cboCountry.Focus

	Else

		intReturn = MsgBox("Selected Options:" & VbCrLf & "Computer Type: " & cboComputerType.Value & VbCrLf & _

			"Build Type: " & cboBuildType.Value & VbCrLf & _

			"Country: " & cboCountry.Value & VbCrLf & VbCrLf & _

			"Do you want to continue?", vbYesNo, "Confirmation")

		If intReturn = vbYes Then

			MsgBox "Running"

		Else

			cboComputerType.Value = "NONE"

			cboBuildType.Value = "NONE"

			cboCountry.Value = "NONE"

			MsgBox "You cancelled the operation."

		End If

	End If

End Sub

 

</script>

</head>

<body style="background-color:#B0C4DE">

        <table width='90%' height='90%' align='center' border='0'>

                <tr>

                        <td align="center" style="font-family: arial; font-size: 24px; font-weight: bold;">

                                Request Details

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Computer Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboComputerType" id="cboComputerType">

                                	<option id="optComputerType" value="NONE"> --- Select --- </option>

                                	<option id="optComputerType" value="Laptop">Laptop</option>

                                	<option id="optComputerType" value="Desktop">Desktop</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Build Type: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboBuildType" id="cboBuildType">

                                	<option id="optBuildType" value="NONE"> --- Select --- </option>

                                	<option id="optBuildType" value="Build">Build</option>

                                	<option id="optBuildType" value="Rebuild">Rebuild</option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='right' style="font-family: arial; font-size: 16px; font-weight: bold;">

                        	Country: 

                        </td>

                        <td align='left' style="font-family: arial; font-size: 16px; font-weight: bold;">

                                <select size="1" name="cboCountry" id="cboCountry">

                                	<option id="optCountry" value="NONE"> --- Select --- </option>

                                </select>

                        </td>

                </tr>

                <tr>

                        <td align='center'>

                                <input type="button" value="Run" name="btn_run" onClick="vbs:Run_Program" style="font-size: 16px;"><br><br>

                        </td>

                        <td align='center'>

                                <input type="button" value="Exit" name="btn_exit" onClick="vbs:window.close" style="font-size: 16px;"><br><br>

                        </td>

                </tr>

        </table>

</body>

</html>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 33821161
Thanks Rob that is brilliant. Sorry about the delay.
Thanks again works great mate. Take care and talk soon.
0
 
LVL 1

Author Closing Comment

by:Simon336697
ID: 33821165
Brilliant as usual Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33826535
No problem. Thanks for the grade.

Rob.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now