Computing.Net > Forums > Programming > Export HTA values to text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Export HTA values to text file

Reply to Message Icon

Name: keridbey
Date: May 7, 2008 at 06:11:02 Pacific
OS: WinXP Pro
CPU/Ram: 1.83 Ghz / 1 Gb
Product: Dell
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: May 7, 2008 at 22:11:35 Pacific
Reply:

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

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



0

Response Number 2
Name: keridbey
Date: May 9, 2008 at 06:12:50 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Export HTA values to text file

passing a value to text file www.computing.net/answers/programming/passing-a-value-to-text-file-/18831.html

printing variable to text file www.computing.net/answers/programming/printing-variable-to-text-file/14677.html

HTML How do I write to text file? www.computing.net/answers/programming/html-how-do-i-write-to-text-file/9317.html