0

I'm creating an HTA from which to run some external VBS files. I need to pass from the HTA to the VBS files, the data of some forms (Radio Button). What should I add to the HTA file to accomplish it? And in VBS?

This is the code I have created so far:

<head><title>Dashboard_Script</title></head>
<meta http-equiv="x-ua-compatible" content="IE=10">
<Script language="VBScript">Set Wss=CreateObject("WScript.Shell")</script>

<body><table><tr><td align="center">

<br><br> DASHBOARD SCRIPTS<br>

<form name="Form1">

<input type="Button" name="Button1" value="SalesReport ">

           
<SCRIPT FOR="Button1" EVENT="onClick" LANGUAGE="VBScript">

Wss.Run("C:\SalesReport.vbs")

</SCRIPT>

<table>

<tr>

<p>Please select Month from:</p>

<th><input type="radio" id="age1" name="age1" value="1">

<label for="age1">1</label><br></th>

<th><input type="radio" id="age1" name="age1" value="2">

<label for="age2">2</label><br></th>

.........................................................
.........................................................

</tr>

</table>

</fieldset>

</form>
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
MicBi
  • 13
  • 1
  • 1
    Sales report? That sounds like something that should be done as a web page that can be run in any browser on any platform, including mobile. HTAs should only be considered when you're trying to create an app that is specifically for Windows and must have access to the file system and/or registry. – LesFerch Dec 11 '22 at 15:08
  • 1
    If you are determined to do this as an HTA, it would be best to put all the VBScript code in the HTA. Barring that, you can pass data on the command line, via the registry, or via a file (possibly INI or XML format). – LesFerch Dec 11 '22 at 15:11
  • Hi LesFerch, thanks for your commments. "Sales report" is a VBscript of an ERP script. I'd prefer to have distinct the HTA for: make the selection of the variable (Months&Year) to pass to the VBS files and run the different Vbs files. From all the different VBS files. Tks! – MicBi Dec 12 '22 at 23:15
  • Command line arguments should work fine. There are good references [here](https://vbsedit.com/faq/arguments.asp) and [here](https://ss64.com/vb/syntax-args.html). Or ask ChatGPT the question "How do I use command line arguments with vbscript?". – LesFerch Dec 13 '22 at 05:39
  • After reading your question again, it occurred to me that you're main concern is how to get the selected month as a variable to be passed to the VBS script. See my posted answer for details on that. – LesFerch Dec 13 '22 at 19:26
  • Also note that using `content="IE=10"` is fine, but you will need to use `content="IE=9"` if you want to use any of the special `HTA:Application` settngs (unless you do a more complex two file script). Since you're dong basic stuff, I recommend using `content="IE=9"`. – LesFerch Dec 13 '22 at 19:29

1 Answers1

1

Don't use a form. That's for passing data to a server. You can get the value of the selected radio button, but since you must iterate through radio buttons to find out which one is selected, you can just use your loop counter as the month index. Also consider using a Select menu or a series of buttons. The code below shows all three methods. In all cases, it passes the month index on the command line to the VBS script. The code below passes a value of 1-12. However, if the receiving script is set up with an array for the months, it may be more convenient to pass a zero based index (i.e. 0-11). It's a small adjustment.

This code can be expanded, of course, for additional parameters, such as a year.

Note that the code is using MsgBox for debugging purposes. Also, avoid using tables. When it comes time to make it pretty, use Divs with classes and CSS for styling.

<!DOCTYPE html>
<html>
<head>
<title>Dashboard_Script</title>
<meta charset="UTF-8" http-equiv="x-ua-compatible" content="IE=9">
<script language="VBScript">
Set oWSH=CreateObject("WScript.Shell")

Sub SalesReport1
  For i = 0 To 11
    If Age1(i).Checked Then Exit For
  Next
  If i<12 Then
    MsgBox "C:\SalesReport.vbs " & i+1
    'oWSH.Run("C:\SalesReport.vbs " & i+1)
  End If
End Sub

Sub SalesReport2
  If Age2.SelectedIndex<>0 Then
    MsgBox "C:\SalesReport.vbs " & Age2.SelectedIndex
    'oWSH.Run("C:\SalesReport.vbs " & Age2.SelectedIndex)
  End If
End Sub

Sub SalesReport3(i)
  MsgBox "C:\SalesReport.vbs " & i
  'oWSH.Run("C:\SalesReport.vbs " & i)
End Sub

</script>
</head>
<body>
<h2>Dashboard Scripts</h2>
<input type=button value=SalesReport onclick=SalesReport1()>
Please select Month:<br>
<input type=radio name=Age1>January
<input type=radio name=Age1>February
<input type=radio name=Age1>March
<input type=radio name=Age1>April
<input type=radio name=Age1>May
<input type=radio name=Age1>June
<input type=radio name=Age1>July
<input type=radio name=Age1>August
<input type=radio name=Age1>September
<input type=radio name=Age1>October
<input type=radio name=Age1>November
<input type=radio name=Age1>December
<br><br>

<input type=button value=SalesReport onclick=SalesReport2()>
Please select:
<select id=Age2>
<option selected disabled>Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December
</select><br><br>

Click a sales report:<br>
<input type=button value=January onclick=SalesReport3(1)>
<input type=button value=February onclick=SalesReport3(2)>
<input type=button value=March onclick=SalesReport3(3)>
<input type=button value=April onclick=SalesReport3(4)>
<input type=button value=May onclick=SalesReport3(5)>
<input type=button value=June onclick=SalesReport3(6)>
<input type=button value=July onclick=SalesReport3(7)>
<input type=button value=August onclick=SalesReport3(8)>
<input type=button value=September onclick=SalesReport3(9)>
<input type=button value=October onclick=SalesReport3(10)>
<input type=button value=November onclick=SalesReport3(11)>
<input type=button value=December onclick=SalesReport3(12)>
</body>
</html>
LesFerch
  • 1,540
  • 2
  • 5
  • 21
  • Hi LesFerch, a very Big Thanks! I have used your first and second suggestions and now the Dashboard starts to take shape. I can pass from HTA to the VBS multi-parameters (Year; Months; etc.) for every single script. Thanks ever so much for the help. Mic – MicBi Dec 19 '22 at 06:08
  • Another help pls. In case I need to use a how to pass to VBS the value load in the HTA text field? I have set in this way oWSH.Run("C:\SalesReport.vbs " & Test) but maybe I'm missing something cause I have a message in VBS of "out of range". Tks a lot – MicBi Dec 20 '22 at 05:55
  • 1
    Quick answer: `Test.value`. Be sure that you are not using exactly the same name for a VBScript variable as you are using for an element ID. All element IDs must be unique. You can directly pass `Test.value` or first assign it to a VBScript variable (e.g. `MyTest = Test.Value` ). Finally, the `name` attribute is not needed. That's probably only useful with a form being passed back to a server. For a script like yours, you'll generally only use `name` for a group of radio buttons. – LesFerch Dec 20 '22 at 13:15
  • With forms, you can't reference elements directly by ID, but have to use the long hand format of `document.getElementById`. Why are you using a form? – LesFerch Dec 23 '22 at 06:00
  • Hi LesFerch, I' m sorry for the late answer. I have reviewed more carefully your last suggestion about "", to use the "Test.value" and it works "perfectly". You're right no needs to use the forms. I started to use it cause it was the first to work, no other particular reason. Thanks ever so much for the great help! Really appreciate! – MicBi Jan 14 '23 at 07:18