Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to write a VB script for an HTA to go with a batch file that has already been written. The batch file currently prompts the user for several port numbers on a switch (one at the time). I'd like the HTA to show 26 checkboxes (one for each port), and allow the user to check off whatever they need to, click a "Perform Action" button at the bottom, and the HTA will export the numbers to a text file that the batch file can use (comma delimited would probably be the easiest format). This is probably a simple operation, but I've actually not had much luck finding anything on the web for some reason (maybe I'm looking in the wrong places). Here's what I have so far:
<html>
<head>
<HTA:APPLICATION
APPLICATIONNAME="PortCheckboxes"
SCROLL="no"
SINGLEINSTANCE="yes"
>
</head><SCRIPT LANGUAGE="VBScript">
Sub OutputPorts
If Checkbox1.Checked Then
'Here's where the functionality will go.
End If
If Checkbox2.Checked Then
'More functionality, and so on...
End If
End Sub</SCRIPT>
<body>
<input type="checkbox" name="Checkbox1"> 01
<input type="checkbox" name="Checkbox2"> 02
<input type="checkbox" name="Checkbox3"> 03
<input type="checkbox" name="Checkbox4"> 04
<!--...and so on...-->
<input id=runbutton class="button" type="button" value="Perform Action" name="run_button" onClick="OutputPorts">
</body>What might be the best way to go about this? Thanks!!

Oh, where to begin....
1) In the tags, everything after an equals sign should either be a number or in quotes. It may also be a number in quotes.
2) Input tags should appear only inside of <FORM></FORM> tags
3) Your Script tags should be inside the Head tags.
4) There are easier ways to do go about your task than using Copy/Paste 25 times.
5) You probably couldn't find what you were looking for because your functionality is so ambiguous, and the first step of a programmer or scripter is to remove all ambiguity.
With that out of the way, I rewrote your app. It doesn't look pretty, and it doesn't do what you want. That's partly because of the fore mentioned ambiguity, and partly because I couldn't be bothered to take a whole five minutes on your problem.
<html>
<head>
<HTA:APPLICATION
APPLICATIONNAME="PortCheckboxes"
SCROLL="no" SINGLEINSTANCE="yes"><script language="VBScript">
Sub BuildPorts
Dim b, f, i
Set f = Document.Forms("ports")
For i = 0 To 25
f.innerHTML = f.innerHTML _
& "<input type=""checkbox"" name=""chkBx"">" & (i + 1) & "<br>"
NextSet b = Document.createElement("input")
With b
.type = "button"
.value = "Preform Action"
.id = "runbutton"
.name = "runButton"
.attachEvent "onclick", GetRef("OutputPorts")
End With
f.AppendChild b
End Sub
Sub OutputPorts
Dim c, sLine
For Each c In Document.GetElementsByName("chkBx")
sLine = sLine & CStr(Int(c.checked) And 1) & ","
c.checked = False
Next
With CreateObject("Scripting.FileSystemObject")
With .CreateTextFile("a.hta.txt")
.WriteLine Left(sLine, Len(sLine) - 1)
.Close
End With
End With
End Sub
</script>
</head>
<body onload="BuildPorts">
<form id="ports">
</form>
</body>
</html>

Sorry, I've not had a lot of time studying VBS or HTML yet; I've got ideas for solutions, but not a lot of design experience yet; most of what I've learned has just been from picking apart scripts written by others. I will continue to work on this script.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |