Solved

Passing variables between pages (hta/vbs)

Posted on 2010-09-22
16
665 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
Industry Leaders: 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!

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using VBScript. How to obtain the recomended paging file size? 8 109
VMWare Calculate number of processors 10 130
vb6 Where condition on dbo 2 30
Problem to macro 5 20
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…

734 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