在 hta 中搜索多个单选按钮集合
Searching multiple radio button collections in hta
Bellow 是我编写的 hta/vbs 代码,用于动态构建带有单选按钮的表单。
hta 由另一个 vbs 脚本启动,该脚本指定要创建的单选按钮 (yes/no) 集合的数量。
我遇到的问题是循环 While x <= ItemListSize
中的 Sub Write
。我无法让 For Each objRadio in RadioButton&x
检查多个集合。
我已经尝试了现有的和 For Each objRadio in RadioButton[x]
。如果我将它更改为第一个集合 For Each objRadio in RadioButton1
,所有代码都可以工作,但是我无法检查所有其他集合的 .checked
个对象。
我知道这段代码不是很优化。
<head>
<title>Autonomous Maintenance</title>
<HTA:APPLICATION
APPLICATIONNAME="Autonomous Maintenance"
APPLICATION ID="AutoMaintenance"
BORDER="thin"
CAPTION="yes"
ICON="Am.ico"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SHOWINTASKBAR"no"
WINDOWSTATE="normal"
INNERBORDER="yes"
NAVIGABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SINGLEINSTANCE="yes"
SYSMENU="yes"
CONTEXTMENU="yes"
SELECTION="no"
VERSION="1.0"
>
</head>
<script language="VBScript">
Dim LogPath
Dim ItemList
Dim ItemListSize
Dim strHTML
Dim addHeight
arrCommands = Split(AutoMaintenance.commandLine, chr(34))
LogPath = arrCommands(3)
ItemList = arrCommands(5)
ItemList = Split(ItemList, ";")
ItemListSize = uBound(ItemList)
If ItemListSize <= 10 Then
strHTML = strHTML & "<table border='0' >"
y = 1
x = 0
While y <= ItemListSize
strHTML = strHTML & "<tr><td width='120' align='left' valign='middle'>"
strHTML = strHTML & "<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td></tr>"
y = 1 + y
x = 1 + x
addHeight = addHeight + 25
Wend
strHTML = strHTML & "</table>"
Else
If ItemListSize <= 20 Then
strHTML = strHTML & "<table border='0' >"
y = 1
x = 0
While y <= 10
strHTML = strHTML & "<tr><td width='120' align='left' valign='middle'>"
strHTML = strHTML & "<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td>"
y = 1 + y
x = 1 + x
IF y <= ItemListSize Then
strHTML = strHTML & "<td width='50' align='center' valign='middle'></td>"
strHTML = strHTML & "<td width='120' align='left' valign='middle'>"&"<input type='radio' name='RadioButton"&y&"' value'"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td></tr>"
y = 1 + y
x = 1 + x
addHeight = addHeight + 25
End If
Wend
While y <= ItemListSize
strHTML = strHTML & "<tr><td width='120' align='left' valign='middle'>"
strHTML = strHTML & "<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td>"
y = 1 + y
x = 1 + x
IF y <= ItemListSize Then
strHTML = strHTML & "<td width='50' align='center' valign='middle'></td>"
strHTML = strHTML & "<td width='120' align='left' valign='middle'>"&"<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td></tr>"
y = 1 + y
x = 1 + x
addHeight = addHeight + 25
End If
Wend
strHTML = strHTML & "</table>"
addWidth = addWidth + 250
Else
If ItemListSize > 20 Then
MsgBox "To many items to verify!"
window.Close()
End If
End If
End If
Sub Window_Onload
window.resizeTo 480 + addWidth,485 + addHeight
screenWidth = Document.ParentWindow.Screen.AvailWidth
screenHeight = Document.ParentWindow.Screen.AvailHeight
posLeft = (screenWidth - 480 - addWidth) / 2
posTop = (screenHeight - 485 - addHeight) / 2
window.moveTo posLeft, posTop
DataArea.InnerHTML = strHTML
End Sub
Sub Write
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.OpenTextFile(LogPath,2,true)
sTxtArea = document.all("Comments").Value
Dim sItem()
ReDim sItem(0)
x = 1
y = 0
While x <= ItemListSize
Dim Rbutton
For Each objRadio in RadioButton&x
If objRadio.checked Then
sItem(y) = objRadio.value
EntryFound = "True"
ReDim Preserve sItem (UBound(sItem) + 1)
End If
Next
x = x + 1
y = y + 1
If EntryFound <> "True" Then
MsgBox "Please verify all items."
Exit Sub
End IF
Wend
Answers = Join(sItem, ";")
oFIle.Write sTxtArea & ";" & Answers
oFile.close
window.Close()
End Sub
</script>
<body>
<body STYLE="font:12 pt arial; color:black; background-color:white">
<div align="center">
<p>
<img id = "Logo" alt="MagellanLogo" style="height: 57px; width: 232px" src= "MagellanLogo.jpg" />
<br>
<font style="font:15 pt arial black"><Text>Autonomous Maintenance</Text></font>
<br>
<Text>Are these items acceptable:</Text><br>
<br>
<span id ="DataArea"></span>
<br>
<Text>Comments</Text><br>
<textarea name="Comments" cols=50 rows=10></textarea>
</p>
<p>
<font style="font:12 pt arial"> Click bellow to complete </font>
<br>
<font style="font:8 pt arial"> By clicking bellow you accept that you have completed the autonomous maintenance. </font>
<br>
<input type="button" value="Finish" name="run_button" onclick="Write">
</p>
</div>
</body>
而不是
For Each objRadio in RadioButton&x 'or similar construction
使用Eval
函数如下:
For Each objRadio in Eval("RadioButton" & CStr(x))
Poorly documented 不过应该可以。
Bellow 是我编写的 hta/vbs 代码,用于动态构建带有单选按钮的表单。
hta 由另一个 vbs 脚本启动,该脚本指定要创建的单选按钮 (yes/no) 集合的数量。
我遇到的问题是循环 While x <= ItemListSize
中的 Sub Write
。我无法让 For Each objRadio in RadioButton&x
检查多个集合。
我已经尝试了现有的和 For Each objRadio in RadioButton[x]
。如果我将它更改为第一个集合 For Each objRadio in RadioButton1
,所有代码都可以工作,但是我无法检查所有其他集合的 .checked
个对象。
我知道这段代码不是很优化。
<head>
<title>Autonomous Maintenance</title>
<HTA:APPLICATION
APPLICATIONNAME="Autonomous Maintenance"
APPLICATION ID="AutoMaintenance"
BORDER="thin"
CAPTION="yes"
ICON="Am.ico"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SHOWINTASKBAR"no"
WINDOWSTATE="normal"
INNERBORDER="yes"
NAVIGABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SINGLEINSTANCE="yes"
SYSMENU="yes"
CONTEXTMENU="yes"
SELECTION="no"
VERSION="1.0"
>
</head>
<script language="VBScript">
Dim LogPath
Dim ItemList
Dim ItemListSize
Dim strHTML
Dim addHeight
arrCommands = Split(AutoMaintenance.commandLine, chr(34))
LogPath = arrCommands(3)
ItemList = arrCommands(5)
ItemList = Split(ItemList, ";")
ItemListSize = uBound(ItemList)
If ItemListSize <= 10 Then
strHTML = strHTML & "<table border='0' >"
y = 1
x = 0
While y <= ItemListSize
strHTML = strHTML & "<tr><td width='120' align='left' valign='middle'>"
strHTML = strHTML & "<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td></tr>"
y = 1 + y
x = 1 + x
addHeight = addHeight + 25
Wend
strHTML = strHTML & "</table>"
Else
If ItemListSize <= 20 Then
strHTML = strHTML & "<table border='0' >"
y = 1
x = 0
While y <= 10
strHTML = strHTML & "<tr><td width='120' align='left' valign='middle'>"
strHTML = strHTML & "<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td>"
y = 1 + y
x = 1 + x
IF y <= ItemListSize Then
strHTML = strHTML & "<td width='50' align='center' valign='middle'></td>"
strHTML = strHTML & "<td width='120' align='left' valign='middle'>"&"<input type='radio' name='RadioButton"&y&"' value'"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td></tr>"
y = 1 + y
x = 1 + x
addHeight = addHeight + 25
End If
Wend
While y <= ItemListSize
strHTML = strHTML & "<tr><td width='120' align='left' valign='middle'>"
strHTML = strHTML & "<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td>"
y = 1 + y
x = 1 + x
IF y <= ItemListSize Then
strHTML = strHTML & "<td width='50' align='center' valign='middle'></td>"
strHTML = strHTML & "<td width='120' align='left' valign='middle'>"&"<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => Yes'>Yes<input type='radio' name='RadioButton"&y&"' value='"&ItemList(x)&" => No'>No</td>"
strHTML = strHTML & "<td align='left' valign='middle'>"&ItemList(x)&"</td></tr>"
y = 1 + y
x = 1 + x
addHeight = addHeight + 25
End If
Wend
strHTML = strHTML & "</table>"
addWidth = addWidth + 250
Else
If ItemListSize > 20 Then
MsgBox "To many items to verify!"
window.Close()
End If
End If
End If
Sub Window_Onload
window.resizeTo 480 + addWidth,485 + addHeight
screenWidth = Document.ParentWindow.Screen.AvailWidth
screenHeight = Document.ParentWindow.Screen.AvailHeight
posLeft = (screenWidth - 480 - addWidth) / 2
posTop = (screenHeight - 485 - addHeight) / 2
window.moveTo posLeft, posTop
DataArea.InnerHTML = strHTML
End Sub
Sub Write
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.OpenTextFile(LogPath,2,true)
sTxtArea = document.all("Comments").Value
Dim sItem()
ReDim sItem(0)
x = 1
y = 0
While x <= ItemListSize
Dim Rbutton
For Each objRadio in RadioButton&x
If objRadio.checked Then
sItem(y) = objRadio.value
EntryFound = "True"
ReDim Preserve sItem (UBound(sItem) + 1)
End If
Next
x = x + 1
y = y + 1
If EntryFound <> "True" Then
MsgBox "Please verify all items."
Exit Sub
End IF
Wend
Answers = Join(sItem, ";")
oFIle.Write sTxtArea & ";" & Answers
oFile.close
window.Close()
End Sub
</script>
<body>
<body STYLE="font:12 pt arial; color:black; background-color:white">
<div align="center">
<p>
<img id = "Logo" alt="MagellanLogo" style="height: 57px; width: 232px" src= "MagellanLogo.jpg" />
<br>
<font style="font:15 pt arial black"><Text>Autonomous Maintenance</Text></font>
<br>
<Text>Are these items acceptable:</Text><br>
<br>
<span id ="DataArea"></span>
<br>
<Text>Comments</Text><br>
<textarea name="Comments" cols=50 rows=10></textarea>
</p>
<p>
<font style="font:12 pt arial"> Click bellow to complete </font>
<br>
<font style="font:8 pt arial"> By clicking bellow you accept that you have completed the autonomous maintenance. </font>
<br>
<input type="button" value="Finish" name="run_button" onclick="Write">
</p>
</div>
</body>
而不是
For Each objRadio in RadioButton&x 'or similar construction
使用Eval
函数如下:
For Each objRadio in Eval("RadioButton" & CStr(x))
Poorly documented 不过应该可以。