HTA:如何从每个下拉列表中获取值并进行搜索?

时间:2015-04-09 20:44:35

标签: vbscript hta

我正在尝试使这个HTA工作,它的作用是从每个下拉列表中添加所有值并相应地搜索可以从另一个按钮中选择的目录。我只能制作这个HTA的形式,但不知道如何使搜索工作。

另外,如何将目录选择按钮移动到行首? 所以用户可以先拿起目录,然后选择他们想要搜索的内容。

<html>
<head>
<HTA:APPLICATION ID="2014-03"
   applicationName="2014-03"
   version="1.1"
    BORDER="thin"
    BORDERSTYLE="static"
    CAPTION="Yes"
    CONTEXTMENU="no"
    ICON="C:\icon\32x32.ico"
    INNERBORDER="no"
    MAXIMIZEBUTTON="no"
    MINIMIZEBUTTON="no"
    NAVIGATABLE="no"
    SCROLL="no"
    SCROLLFLAT="no"
    SELECTION="no"
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    WINDOWSTATE="normal" 
>

<SCRIPT LANGUAGE="VBScript">

    Sub RunSearch_OnClick()
        msgBox "Success!"
    End Sub 

    Sub TestSub
        For Each objOption in OptionChooser.Options
            If objOption.Selected Then
                Msgbox objOption.InnerText
            End If
        Next
    End Sub

        Sub TestSub1
        For Each objOption in OptionChooser.Options
            If objOption.Selected Then
                Msgbox objOption.InnerText
            End If
        Next
    End Sub


    Sub WindowsLoad

    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder (0, "Select The Folder To Enumerate :", (0))
    If objFolder Is Nothing Then
    Wscript.Quit
    Else
    Set objFolderItem = objFolder.Self
    objPath = objFolderItem.Path
    End If

    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFso.GetFolder(objPath)
    For each objFile in objFolder.Files
    If objFolder.Files.Count > 0 Then

    Window.Document.Title = "Information For " & objPath
    strHtml = strHtml & "<td><Font color = Blue>" & objFile.Name & "</font></Br>"
    DataArea.InnerHtml = strHtml
    End If
    Next
    End Sub

</SCRIPT>
</head>

<body>


<select id=extension size="1" name="OptionChooser" onChange="TestSub">
    <option value="0">Selet File Type</option>
    <option value="1">.txt</option>
    <option value="2">.pdf</option>
    <option value="3">.jpg</option>
    <option value="4">.mp3</option>
</select>

<select id=year size="1" name="OptionChooser" onChange="TestSub1">
    <option value="0">Select Year</option>
    <option value="1">2014</option>
    <option value="2">2013</option>
    <option value="3">2012</option>
    <option value="3">2011</option>
    <option value="3">2010</option>
</select>

<select id=month size="1" name="OptionChooser" onChange="TestSub2">
    <option value="0">Select Month</option>
    <option value="1">01</option>
    <option value="2">02</option>
    <option value="3">03</option>
    <option value="1">04</option>
    <option value="2">05</option>
    <option value="3">06</option>
    <option value="1">07</option>
    <option value="2">08</option>
    <option value="3">09</option>
    <option value="1">10</option>
    <option value="2">11</option>
    <option value="3">12</option>

</select>



<input Type = "Button" Value = "Browse For Folder" Name = "Run_Button" onClick = "WindowsLoad"><p></td>
<input type="button" value="Search" name="RunSearch">

</body>

</html>

最终的HTA应如下所示,搜索结果需要在下拉列表下方显示为可滚动窗口中的文本文件并具有文件的完整路径。

enter image description here

1 个答案:

答案 0 :(得分:2)

在下一个HTA中,只需进行必要的更改,将下拉列表下方的搜索结果显示为可滚动的文本区域,并具有文件的完整路径。

  • 一开始,系统会提示用户选择初始目录(请参阅WindowsLoad程序中的Window_Onload电话;然后所有文件显示为尚未选择搜索条件。
  • 扩展程序的代码中完成搜索,仅显示可能的操作方法方法(少数几种方法之一)。
  • 使用了简单的 StyleSheet
  • 一些变量定义脚本(应用程序)全局以保持其在所有过程中的可见性。
  • 进一步的基本更改:请参阅下面的代码。

29548613.HTA look

代码:

<html>
<head>
<HTA:APPLICATION ID="2014-03"
   applicationName="2014-03"
   version="1.1"
    BORDER="thin"
    BORDERSTYLE="static"
    CAPTION="Yes"
    CONTEXTMENU="no"
    ICON="C:\icon\32x32.ico"
    INNERBORDER="no"
    MAXIMIZEBUTTON="no"
    MINIMIZEBUTTON="no"
    NAVIGATABLE="no"
    SCROLL="no"
    SCROLLFLAT="no"
    SELECTION="no"
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    WINDOWSTATE="normal" 
>

<!--
'************************
'* StyleSheet
'************************
-->
<style>
BODY
{
   background-color: buttonface;
   font-family: Arial, Helvetica, sans-serif;
   font-size: 8pt;
   margin-top: 2px;
   margin-left: 8px;
   margin-right: 3px;
   margin-bottom: 3px;
}
.button
{
   font-family: Arial, Helvetica, sans-serif;
   font-size: 8pt;
   width: 40px;
}
textarea
{
   background-color: yellow;
   font-family: Arial;
   font-size: 8pt;
   margin-left: 3px;
   margin-right: 3px;
}
</style>

<SCRIPT LANGUAGE="VBScript">

'************************
'* Global Variables
'************************
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Shell.Application")
    objPath = ""
    strHtml = ""
    Chooser0 = ""
    Chooser1 = ""
    Chooser2 = ""

'************************
'* Window_Onload
'************************
Sub Window_Onload

    self.Focus()
    self.ResizeTo 800,600

    DataArea.InnerHTML = "<textarea cols=122 rows=25></textarea>"

    WindowsLoad

End Sub


Sub RunSearch_OnClick()
    'msgBox "Success!"
    WindowsLoad
End Sub 

Sub TestSub
  If OptionChooser.Value = "0" Then
    Chooser0 = ""
  Else
    For Each objOption in OptionChooser.Options
        If objOption.Selected Then
          Chooser0 = objOption.InnerText
          Exit For
        End If
    Next
  End If
End Sub

Sub TestSub1
    For Each objOption in OptionChooser1.Options
        If objOption.Selected Then
            Msgbox objOption.InnerText
        End If
    Next
End Sub

Sub TestSub2
    For Each objOption in OptionChooser2.Options
        If objOption.Selected Then
            Msgbox objOption.InnerText
        End If
    Next
End Sub

Sub whichFolder
  prevPath = objPath
  Set objFolder = objShell.BrowseForFolder _
      (0, "Select The Folder To Enumerate :", (0))
  If objFolder Is Nothing Then
    msgBox "Bye!"
    self.Close()
  Else
    Set objFolderItem = objFolder.Self
    objPath = objFolderItem.Path
  End If
  If prevPath <> "" then WindowsLoad
End Sub

Sub WindowsLoad
  If objPath = "" Then
    whichFolder
  End If

  Set objFolder = objFso.GetFolder(objPath)

  Window.Document.Title = "Information For " & objPath & " " & Chooser0
  strHtml = "<textarea cols=122 rows=25>"

  ShowSubFolders objFolder, Chooser0

  DataArea.InnerHtml = strHtml
End Sub

Sub ShowSubFolders(fFolder, strExt)
    'strHtml = strHtml & Chr(10) & fFolder.Path & Chr(10)
    Set objFolder = objFSO.GetFolder(fFolder.Path)
    Set colFiles = objFolder.Files
    For Each objFile in colFiles
        If strExt = "" OR UCase(strExt) = _
          "." & UCase(objFSO.GetExtensionName(objFile.name)) Then
            strHtml = strHtml & objFile.Path & Chr(10)
        End If
    Next

    For Each Subfolder in fFolder.SubFolders
        ShowSubFolders Subfolder, strExt
    Next
End Sub

</SCRIPT>
</head>

<body>

<select id=extension size="1" name="OptionChooser" onChange="TestSub">
    <option value="0">Selet File Type</option>
    <option value="1">.txt</option>
    <option value="2">.pdf</option>
    <option value="3">.jpg</option>
    <option value="4">.mp3</option>
</select>

<select id=year size="1" name="OptionChooser1" onChange="TestSub1">
    <option value="0">Select Year</option>
    <option value="1">2014</option>
    <option value="2">2013</option>
    <option value="3">2012</option>
    <option value="3">2011</option>
    <option value="3">2010</option>
</select>

<select id=month size="1" name="OptionChooser2" onChange="TestSub2">
    <option value="0">Select Month</option>
    <option value="1">01</option>
    <option value="2">02</option>
    <option value="3">03</option>
    <option value="1">04</option>
    <option value="2">05</option>
    <option value="3">06</option>
    <option value="1">07</option>
    <option value="2">08</option>
    <option value="3">09</option>
    <option value="1">10</option>
    <option value="2">11</option>
    <option value="3">12</option>
</select>

<input Type = "button" Value = "Browse For Folder" 
        Name = "Run_Button" onClick = "whichFolder"><p>

<input type="button" value="Search" name="RunSearch"><p>

<div id="DataArea" name="DataArea"></div>

</body>

</html>