Drop down menu hta vbscript读取文本文件,拆分数据并填充下拉框,删除空白选项
下面的示例中有3个文件。 执行dropdownboxtest.hta将在msgboxes中显示所需的正确数据。 问题是下拉框: IP数据填写正确,下拉菜单填写正确(所有数据均存在)。问题是第一个选项是空的,我已经尝试使用下面的代码,以“colin”为例,创建“selected”选项:Drop down menu hta vbscript读取文本文件,拆分数据并填充下拉框,删除空白选项,drop-down-menu,vbscript,text-files,hta,Drop Down Menu,Vbscript,Text Files,Hta,下面的示例中有3个文件。 执行dropdownboxtest.hta将在msgboxes中显示所需的正确数据。 问题是下拉框: IP数据填写正确,下拉菜单填写正确(所有数据均存在)。问题是第一个选项是空的,我已经尝试使用下面的代码,以“colin”为例,创建“selected”选项: document.getElementById("savedhostname").value = last_hostname_connected_value 或 已保存的\u last.cfg last_ho
document.getElementById("savedhostname").value = last_hostname_connected_value
或
已保存的\u last.cfg
last_hostname_connected = "colin"
last_IP_connected = "192.168.1.8"
savedhosts.txt
andy;192.168.1.5
brian;192.168.1.6
colin;192.168.1.8
david;192.168.1.15
eddie;192.168.1.54
dropdownboxtest.hta
<!DOCTYPE html>
<html>
<head>
<title>Test Dropdown Box</title>
<HTA:APPLICATION
ID="objHTA_Info"
APPLICATIONNAME="Test Dropdown Box"
SINGLEINSTANCE="no"
SCROLL="no"
BORDER="Thin"
BorderStyle="Raised"
Icon="#"
MaximizeButton="No"
>
<script language="javascript">
window.resizeTo (810, 634);
window.moveTo((screen.width - 10) / 2, (screen.height - 634) / 2);
</script>
<SCRIPT LANGUAGE="VBScript">
Dim last_hostname_connected_value, last_IP_connected_value
Sub Window_onLoad
With (CreateObject("Scripting.FileSystemObject"))
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If .FileExists("saved_last.cfg") Then
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ReadTextFile = FSO.OpenTextFile("saved_last.cfg", 1) ' Open text with read only mode
Do Until ReadTextFile.AtEndOfStream
Textline = ReadTextFile.Readline()
If Instr(Textline, "last_hostname_connected =") Then
last_hostname_connected_value = Split(Textline, "=")(1)
last_hostname_connected_value = Replace(last_hostname_connected_value, Chr(34), "")
last_hostname_connected_value = LTrim(last_hostname_connected_value)
MsgBox "last_hostname_connected_value = " & last_hostname_connected_value
End If
If Instr(Textline, "last_IP_connected =") Then
last_IP_connected_value = Split(Textline, "=")(1)
last_IP_connected_value = Replace(last_IP_connected_value, Chr(34), "")
last_IP_connected_value = LTrim(last_IP_connected_value)
MsgBox "last_IP_connected_value : " & last_IP_connected_value
End If
Loop
End If
End With
Set obj = CreateObject("Scripting.FileSystemObject") 'Creating a File Object
Const ForReading = 1 'Defining Constant Value to read from a file
Set obj1 = obj.OpenTextFile("savedhosts.txt", ForReading) 'Opening a text file and reading text from it
Dim str,str1,objOption
'str=obj1.ReadAll 'All text from the file is read using ReadAll
'Msgbox str 'Contents of a file will be displayed through message box
'Do while obj1.AtEndofStream 'Reading text line wise using Do Loop and ReadLine
' str1=obj1.ReadLine
' Msgbox str1
'Loop
Call ClearHostnameListbox()
Do Until obj1.AtEndOfStream
strNextLine = obj1.ReadLine
arrServiceList = Split(strNextLine, ";")
'MsgBox "arrServiceList(0) = " & arrServiceList(0)
'MsgBox "arrServiceList(1) = " & arrServiceList(1)
Set objOption = document.createElement("OPTION")
objOption.Text = arrServiceList(0)
objOption.Value = arrServiceList(1)
savedhostname.Add(objOption)
'document.getElementById("savedhostname").value=77747
Loop
'MsgBox "arrServiceList(0) = " & arrServiceList(0)
'MsgBox "arrServiceList(1) = " & arrServiceList(1)
obj1.Close 'Closing a File
Set obj=Nothing 'Releasing File object
document.getElementById("savedhostname").value=last_hostname_connected_value
MsgBox "End of SUB check last_hostname_connected_value = " & last_hostname_connected_value
document.getElementById("IP-Input").value = last_IP_connected_value
End Sub
</script>
<SCRIPT LANGUAGE="VBScript">
Sub ClearHostnameListbox()
For Each objOption in savedhostname.Options
objOption.RemoveNode
Next
End Sub
</script>
</head>
<body>
TEST
<br>
IP: <input type='text' maxlength="15" class="enterhostip" size=22 id="IP-Input" name="hostname_IP" />
<br>
Saved Name : <select id="savedhostname" selected="savedhostname" maxlength="20" name="savedhostname" class="savedhostname" value=""></select>
</body>
</html>
测试下拉框
window.resizeTo(810634);
窗口。移动到((屏幕宽度-10)/2,(屏幕高度-634)/2);
调暗上次\u主机名\u连接\u值、上次\u IP\u连接\u值
子窗口加载
使用(CreateObject(“Scripting.FileSystemObject”))
Dim objFSO
设置objFSO=CreateObject(“Scripting.FileSystemObject”)
如果.FileExists(“saved_last.cfg”),则
设置FSO=CreateObject(“Scripting.FileSystemObject”)
设置ReadTextFile=FSO.OpenTextFile(“saved_last.cfg”,1)”以只读模式打开文本
直到ReadTextFile.AtEndOfStream
Textline=ReadTextFile.Readline()
如果Instr(文本行,“last_hostname_connected=”),则
上次\u主机名\u连接\u值=拆分(文本行,“=”)(1)
last_hostname_connected_value=替换(last_hostname_connected_value,Chr(34),“”)
last_hostname_connected_value=LTrim(last_hostname_connected_value)
MsgBox“last\u hostname\u connected\u value=“&last\u hostname\u connected\u value
如果结束
如果Instr(文本行,“last_IP_connected=”),则
上次连接的IP值=拆分(文本行“=”)(1)
last_IP_connected_value=替换(last_IP_connected_value,Chr(34),“”)
上次IP连接值=LTrim(上次IP连接值)
MsgBox“上次IP连接的值:&上次IP连接的值”
如果结束
环
如果结束
以
设置obj=CreateObject(“Scripting.FileSystemObject”)“创建文件对象
Const ForReading=1'定义从文件读取的常量值
设置obj1=obj.OpenTextFile(“savedhosts.txt”,ForReading)“打开文本文件并从中读取文本
Dim str,str1,objOption
“str=obj1.ReadAll”使用ReadAll读取文件中的所有文本
文件的“Msgbox str”内容将通过消息框显示
“Do while obj1.AtEndofStream”使用Do循环和ReadLine逐行读取文本
'str1=obj1.ReadLine
'Msgbox str1
'循环
调用ClearHostnameListbox()
直到obj1.AtEndOfStream
strNextLine=obj1.ReadLine
arrServiceList=Split(strNextLine,“;”)
“MsgBox”arrServiceList(0)=“&arrServiceList(0)
“MsgBox”arrServiceList(1)=“&arrServiceList(1)
Set objOption=document.createElement(“选项”)
objOption.Text=arrServiceList(0)
objOption.Value=arrServiceList(1)
savedhostname.Add(对象选项)
'document.getElementById(“savedhostname”).value=77747
环
“MsgBox”arrServiceList(0)=“&arrServiceList(0)
“MsgBox”arrServiceList(1)=“&arrServiceList(1)
obj1.关闭“关闭文件”
Set obj=Nothing'释放文件对象
document.getElementById(“savedhostname”).value=last\u hostname\u connected\u value
MsgBox“结束子检查上次\u主机名\u连接的\u值=“&last\u主机名\u连接的\u值
document.getElementById(“IP输入”).value=last\u IP\u connected\u value
端接头
子ClearHostnameListbox()
对于savedhostname.Options中的每个对象选项
改造
下一个
端接头
试验
知识产权:
保存的名称:
很明显,这里发生了一些我无法确定的事情,如果您能提供任何帮助,我们将不胜感激。尝试以下方式:
<!DOCTYPE html>
<html>
<head>
<title>Test Dropdown Box</title>
<HTA:APPLICATION
ID="objHTA_Info"
APPLICATIONNAME="Test Dropdown Box"
SINGLEINSTANCE="no"
SCROLL="no"
BORDER="Thin"
BorderStyle="Raised"
Icon="#"
MaximizeButton="No"
>
<script language="javascript">
window.resizeTo (810, 634);
window.moveTo((screen.width - 10) / 2, (screen.height - 634) / 2);
</script>
<SCRIPT LANGUAGE="VBScript">
Dim last_hostname_connected_value, last_IP_connected_value
Sub Window_onLoad
With (CreateObject("Scripting.FileSystemObject"))
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If .FileExists("saved_last.cfg") Then
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ReadTextFile = FSO.OpenTextFile("saved_last.cfg", 1) ' Open text with read only mode
Do Until ReadTextFile.AtEndOfStream
Textline = ReadTextFile.Readline()
If Instr(Textline, "last_hostname_connected =") Then
last_hostname_connected_value = Split(Textline, "=")(1)
last_hostname_connected_value = Replace(last_hostname_connected_value, Chr(34), "")
last_hostname_connected_value = LTrim(last_hostname_connected_value)
'MsgBox "last_hostname_connected_value = " & last_hostname_connected_value
End If
If Instr(Textline, "last_IP_connected =") Then
last_IP_connected_value = Split(Textline, "=")(1)
last_IP_connected_value = Replace(last_IP_connected_value, Chr(34), "")
last_IP_connected_value = LTrim(last_IP_connected_value)
'MsgBox "last_IP_connected_value : " & last_IP_connected_value
End If
Loop
End If
End With
Call ClearHostnameListbox()
Set obj = CreateObject("Scripting.FileSystemObject") 'Creating a File Object
Const ForReading = 1 'Defining Constant Value to read from a file
Set obj1 = obj.OpenTextFile("savedhosts.txt", ForReading) 'Opening a text file and reading text from it
Dim str,str1,objOption
'str=obj1.ReadAll 'All text from the file is read using ReadAll
'Msgbox str 'Contents of a file will be displayed through message box
'Do while obj1.AtEndofStream 'Reading text line wise using Do Loop and ReadLine
' str1=obj1.ReadLine
' Msgbox str1
'Loop
Do Until obj1.AtEndOfStream
strNextLine = obj1.ReadLine
arrServiceList = Split(strNextLine, ";")
'MsgBox "arrServiceList(0) = " & arrServiceList(0)
'MsgBox "arrServiceList(1) = " & arrServiceList(1)
Set objOption = document.createElement("OPTION")
objOption.Text = arrServiceList(0)
objOption.Value = arrServiceList(1)
savedhostname.Add(objOption)
'document.getElementById("savedhostname").value=77747
Loop
'MsgBox "arrServiceList(0) = " & arrServiceList(0)
'MsgBox "arrServiceList(1) = " & arrServiceList(1)
obj1.Close 'Closing a File
Set obj=Nothing 'Releasing File object
'document.getElementById("savedhostname").value=last_hostname_connected_value
'MsgBox "End of SUB check last_hostname_connected_value = " & last_hostname_connected_value
document.getElementById("IP-Input").value = last_IP_connected_value
End Sub
Sub ClearHostnameListbox()
For Each objOption in savedhostname.Options
objOption.RemoveNode
Next
End Sub
</script>
</head>
<body>
TEST
<br>
IP: <input type='text' maxlength="15" class="enterhostip" size=22 id="IP-Input" name="hostname_IP" />
<br>
Saved Name : <select id="savedhostname" selected="savedhostname" maxlength="20" name="savedhostname" class="savedhostname"></select>
</body>
</html>
测试下拉框
window.resizeTo(810634);
窗口。移动到((屏幕宽度-10)/2,(屏幕高度-634)/2);
调暗上次\u主机名\u连接\u值、上次\u IP\u连接\u值
子窗口加载
使用(CreateObject(“Scripting.FileSystemObject”))
Dim objFSO
设置objFSO=CreateObject(“Scripting.FileSystemObject”)
如果.FileExists(“saved_last.cfg”),则
设置FSO=CreateObject(“Scripting.FileSystemObject”)
设置ReadTextFile=FSO.OpenTextFile(“saved_last.cfg”,1)”以只读模式打开文本
直到ReadTextFile.AtEndOfStream
Textline=ReadTextFile.Readline()
如果Instr(文本行,“last_hostname_connected=”),则
上次\u主机名\u连接\u值=拆分(文本行,“=”)(1)
last_hostname_connected_value=替换(last_hostname_connected_value,Chr(34),“”)
last_hostname_connected_value=LTrim(last_hostname_connected
<!DOCTYPE html>
<html>
<head>
<title>Test Dropdown Box</title>
<HTA:APPLICATION
ID="objHTA_Info"
APPLICATIONNAME="Test Dropdown Box"
SINGLEINSTANCE="no"
SCROLL="no"
BORDER="Thin"
BorderStyle="Raised"
Icon="#"
MaximizeButton="No"
>
<script language="javascript">
window.resizeTo (810, 634);
window.moveTo((screen.width - 10) / 2, (screen.height - 634) / 2);
</script>
<SCRIPT LANGUAGE="VBScript">
Dim last_hostname_connected_value, last_IP_connected_value
Sub Window_onLoad
With (CreateObject("Scripting.FileSystemObject"))
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If .FileExists("saved_last.cfg") Then
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ReadTextFile = FSO.OpenTextFile("saved_last.cfg", 1) ' Open text with read only mode
Do Until ReadTextFile.AtEndOfStream
Textline = ReadTextFile.Readline()
If Instr(Textline, "last_hostname_connected =") Then
last_hostname_connected_value = Split(Textline, "=")(1)
last_hostname_connected_value = Replace(last_hostname_connected_value, Chr(34), "")
last_hostname_connected_value = LTrim(last_hostname_connected_value)
'MsgBox "last_hostname_connected_value = " & last_hostname_connected_value
End If
If Instr(Textline, "last_IP_connected =") Then
last_IP_connected_value = Split(Textline, "=")(1)
last_IP_connected_value = Replace(last_IP_connected_value, Chr(34), "")
last_IP_connected_value = LTrim(last_IP_connected_value)
'MsgBox "last_IP_connected_value : " & last_IP_connected_value
End If
Loop
End If
End With
Call ClearHostnameListbox()
Set obj = CreateObject("Scripting.FileSystemObject") 'Creating a File Object
Const ForReading = 1 'Defining Constant Value to read from a file
Set obj1 = obj.OpenTextFile("savedhosts.txt", ForReading) 'Opening a text file and reading text from it
Dim str,str1,objOption
'str=obj1.ReadAll 'All text from the file is read using ReadAll
'Msgbox str 'Contents of a file will be displayed through message box
'Do while obj1.AtEndofStream 'Reading text line wise using Do Loop and ReadLine
' str1=obj1.ReadLine
' Msgbox str1
'Loop
Do Until obj1.AtEndOfStream
strNextLine = obj1.ReadLine
arrServiceList = Split(strNextLine, ";")
'MsgBox "arrServiceList(0) = " & arrServiceList(0)
'MsgBox "arrServiceList(1) = " & arrServiceList(1)
Set objOption = document.createElement("OPTION")
objOption.Text = arrServiceList(0)
objOption.Value = arrServiceList(1)
savedhostname.Add(objOption)
'document.getElementById("savedhostname").value=77747
Loop
'MsgBox "arrServiceList(0) = " & arrServiceList(0)
'MsgBox "arrServiceList(1) = " & arrServiceList(1)
obj1.Close 'Closing a File
Set obj=Nothing 'Releasing File object
'document.getElementById("savedhostname").value=last_hostname_connected_value
'MsgBox "End of SUB check last_hostname_connected_value = " & last_hostname_connected_value
document.getElementById("IP-Input").value = last_IP_connected_value
End Sub
Sub ClearHostnameListbox()
For Each objOption in savedhostname.Options
objOption.RemoveNode
Next
End Sub
</script>
</head>
<body>
TEST
<br>
IP: <input type='text' maxlength="15" class="enterhostip" size=22 id="IP-Input" name="hostname_IP" />
<br>
Saved Name : <select id="savedhostname" selected="savedhostname" maxlength="20" name="savedhostname" class="savedhostname"></select>
</body>
</html>