Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing variables between pages (hta/vbs)

Posted on 2010-09-22
16
Medium Priority
?
724 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
[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
  • 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
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.

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
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…

636 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