路径中的空格中HTA中未终止的字符串常量



我是Stack的新手,但一直在使用这个网站来解决很多编码问题,所以我知道一些基本知识。我已经试了几个小时(这对我来说是一个很大的问题)来克服这个问题。我正在创建一个本地工具(HTA)来最终管理CSV文件,但我仍停留在第一部分。

我正在创建一个资源管理器类型选择工具,你可以在其中选择根文件夹,它会将每个子文件夹加载为一个按钮,它工作得很好,除非子文件夹有一个空间,它会吐出"Unterminated String Constant"。我已经解决了大多数问题,但由于我希望它使用这个名称进行回调,我不能简单地删除空间或替换它,因为单击它的按钮将不起作用。

如有任何帮助,我们将不胜感激!

附言:它还没有完成,很抱歉没有评论或描述。。。P.S.S.请让我知道你看到的任何角落的东西。。。无论是网站礼仪还是编码。谢谢堆栈溢出对我来说是一个巨大的帮助!!!

问题在线:

strHtml = strHtml & "<td><input type=button value='" & strFolderName & "' name=btn_'" & strFolderName & "' onClick=btnCall('" & objFolder.Name & "')></td><Br>"

完整代码如下:

<html>
    <head>
    <title>CSV Menu Selector</title>
    <hta:application
         scroll="no"
         singleinstance="no"
         windowstate="normal"
    >
    </head>
<script type="text/vbscript">
Dim objPath
Dim Master
Dim Master1
Dim g_date_input ' globally saved input object
Function GetDate(obj)
  div1.style.visibility="visible"
  set g_date_input = obj
End Function
Sub cal1_click()
  g_date_input.value = cal1
  div1.style.visibility="hidden"
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''BrowseFolders'''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub BrowseSub
  Set objShell = CreateObject("Shell.Application")
  Set objFolder = objShell.BrowseForFolder (0, "Select The Folder To Enumerate :", (0),17)
  If objFolder Is Nothing Then
    Exit Sub
  Else
    Set objFolderItem = objFolder.Self
    objPath = objFolderItem.Path
  End If
  ShowData
End Sub
Sub txtFile_OnkeyPress
  If window.event.Keycode = 13 Then
    objPath = txtFile.value
    ShowData
  End If
End Sub
Sub ShowData
  If objPath = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" Then
    objPath = "C:"
  End If
  Set fso = CreateObject("Scripting.FileSystemObject")
  If fso.FolderExists(objPath) Then
    txtFile.value = objPath
  Else
    MsgBox "Unable to use this path:" & vbCrLf & objPath
    Exit Sub
  End If
  Set objFso = CreateObject("Scripting.FileSystemObject")
  Set objFolder = objFso.GetFolder(objPath)
  'For each objFolder in objFolder.Subfolders
  'If objFolder.Subfolders.Count > 0 Then
  strHtml = "<html><body><table>"
//msgbox objFolder.Subfolders.Count
  For each objFolder in objFolder.Subfolders
    Set objOption = Document.createElement("OPTION")
    objOption.text = objFolder.Subfolders
    objOption.value = objFolder.Subfolders
    //msgbox "objFolder: " & objFolder
  strFolderName = Replace(objFolder.Name," ","_")
  strFolderName2 = Replace(objFolder.Name," ","&nbsp")
  //msgbox "NoBlanks: " & strFolderName
  Window.Document.Title = "Information For " & objPath
  strHtml = strHtml & "<td><input type=button value='" & strFolderName & "' name=btn_'" & strFolderName & "' onClick=btnCall('" & objFolder.Name & "')></td><Br>"
  //Msgbox strHtml
  'End If
  Next
  strHtml = strHtml & "</table></body></html>"
  Msgbox strHtml
  DataArea.InnerHtml = strHtml
End Sub
Sub btnCall(strBtnName)
    objPath = objPath & "" & strBtnName
    msgbox "objPath: " & objPath
    ShowData
End Sub
Sub CheckMaster
  Master = txtFile.value
  If txtFile.value ="" Then
    msgbox "Please Enter Database Name"
  Else
    msgBox "Master is: " & Master
    TrimMaster
  End If
End Sub
Sub TrimMaster
    Master1 = Mid(txtFile.value, 1+InStrRev(txtFile.value,""))
    msgBox "Master1 is: " & Master1
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
</script>
<body>
<div>
  <!-- Begin Browse for Folder -->
  <input type="text" name="txtFile" size="50" />
  <input id="btnBrowse" type="button" value="Browse..." onClick="BrowseSub" />
  <input type="button" value="Submit" name="run_button" onClick="CheckMaster"><br></td>
  <!-- End Browse for Folder -->
  <!-- Begin Browse for Folder-->
  <input Type="Button" Value="Reset" onClick="location.reload()" /><p></td>
  <!-- <input Type="Button" Value="Browse For Folder" Name="Run_Button" onClick="BrowseSub"><p></td> -->
  <Span Id = "DataArea"></Span><Div Align = "Center">
  <!-- <select style="background-color:#ffb7d6" size="8" onActivate=LoadDropDown name="Scanners" onChange="TestSub"> -->
  <!-- End Browse for Folder -->
  <!-- Begin Get Dates -->
  <!-- <input id="ddate1" type="text" value="click here" onclick="GetDate(me)"> -->
  <!-- <input id="ddate2" type="text" value="click here" onclick="GetDate(me)"> -->
  <div id="div1" style="visibility:hidden;">
    <object id="cal1" classid="clsid:8E27C92B-1264-101C-8A2F-040224009C02"></object>
  </div>
  <!-- End Get Dates -->
</div>
</body>
</html>

错误的引号位置。拆分以使其更可见

Dim td
    td = Array( _ 
            "<td>" _ 
            , "<input type='button'" _ 
            , " value='", objFolder.Name, "'" _ 
            , " name='btn_" , strFolderName, "'" _ 
            , " onClick='btnCall(""" , objFolder.Name , """)'" _ 
            , "></td><br>" _ 
        )
    strHtml = strHtml & Join(td,"")

尝试使用这个有用的函数DblQuote(Str)将双引号添加到变量中

Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function

所以你的代码变成了这样:

<html>
    <head>
    <title>CSV Menu Selector</title>
    <hta:application
         scroll="no"
         singleinstance="no"
         windowstate="normal"
    >
    </head>
<script type="text/vbscript">
Dim objPath
Dim Master
Dim Master1
Dim g_date_input ' globally saved input object
Function GetDate(obj)
  div1.style.visibility="visible"
  set g_date_input = obj
End Function
Sub cal1_click()
  g_date_input.value = cal1
  div1.style.visibility="hidden"
End Sub
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''BrowseFolders'''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub BrowseSub
  Set objShell = CreateObject("Shell.Application")
  Set objFolder = objShell.BrowseForFolder (0, "Select The Folder To Enumerate :", (0),17)
  If objFolder Is Nothing Then
    Exit Sub
  Else
    Set objFolderItem = objFolder.Self
    objPath = objFolderItem.Path
  End If
  ShowData
End Sub
Sub txtFile_OnkeyPress
  If window.event.Keycode = 13 Then
    objPath = txtFile.value
    ShowData
  End If
End Sub
Sub ShowData
  If objPath = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" Then
    objPath = "C:"
  End If
  Set fso = CreateObject("Scripting.FileSystemObject")
  If fso.FolderExists(objPath) Then
    txtFile.value = objPath
  Else
    MsgBox "Unable to use this path:" & vbCrLf & objPath
    Exit Sub
  End If
  Set objFso = CreateObject("Scripting.FileSystemObject")
  Set objFolder = objFso.GetFolder(objPath)
  'For each objFolder in objFolder.Subfolders
  'If objFolder.Subfolders.Count > 0 Then
  strHtml = "<html><body><table>"
//msgbox objFolder.Subfolders.Count
  For each objFolder in objFolder.Subfolders
    Set objOption = Document.createElement("OPTION")
    objOption.text = objFolder.Subfolders
    objOption.value = objFolder.Subfolders
    //msgbox "objFolder: " & objFolder
  strFolderName = Replace(objFolder.Name," ","_")
  strFolderName2 = Replace(objFolder.Name," ","&nbsp")
  //msgbox "NoBlanks: " & strFolderName
  Window.Document.Title = "Information For " & DblQuote(objPath)
  'strHtml = strHtml & "<td><input type=button value='" & strFolderName & "' name=btn_'" & strFolderName & "' onClick=btnCall(" & objFolder.Name & ")></td><Br>"
  Dim td
    td = Array( _ 
            "<td>" _ 
            , "<input type='button'" _ 
            , " value='", objFolder.Name, "'" _ 
            , " name='btn_" , strFolderName, "'" _ 
            , " onClick='btnCall(" , DblQuote(objFolder.Name) , ")'" _ 
            , "></td><br>" _ 
        )
    strHtml = strHtml & Join(td,"")
  //Msgbox strHtml
  'End If
  Next
  strHtml = strHtml & "</table></body></html>"
  Msgbox strHtml
  DataArea.InnerHtml = strHtml
End Sub
Sub btnCall(strBtnName)
    objPath = objPath & "" & strBtnName
    msgbox "objPath: " & DblQuote(objPath)
    ShowData
End Sub
Sub CheckMaster
  Master = txtFile.value
  If txtFile.value ="" Then
    msgbox "Please Enter Database Name"
  Else
    msgBox "Master is: " & Master
    TrimMaster
  End If
End Sub
Sub TrimMaster
    Master1 = Mid(txtFile.value, 1+InStrRev(txtFile.value,""))
    msgBox "Master1 is: " & Master1
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
</script>
<body>
<div>
  <!-- Begin Browse for Folder -->
  <input type="text" name="txtFile" size="50" />
  <input id="btnBrowse" type="button" value="Browse..." onClick="BrowseSub" />
  <input type="button" value="Submit" name="run_button" onClick="CheckMaster"><br></td>
  <!-- End Browse for Folder -->
  <!-- Begin Browse for Folder-->
  <input Type="Button" Value="Reset" onClick="location.reload()" /><p></td>
  <!-- <input Type="Button" Value="Browse For Folder" Name="Run_Button" onClick="BrowseSub"><p></td> -->
  <Span Id = "DataArea"></Span><Div Align = "Center">
  <!-- <select style="background-color:#ffb7d6" size="8" onActivate=LoadDropDown name="Scanners" onChange="TestSub"> -->
  <!-- End Browse for Folder -->
  <!-- Begin Get Dates -->
  <!-- <input id="ddate1" type="text" value="click here" onclick="GetDate(me)"> -->
  <!-- <input id="ddate2" type="text" value="click here" onclick="GetDate(me)"> -->
  <div id="div1" style="visibility:hidden;">
    <object id="cal1" classid="clsid:8E27C92B-1264-101C-8A2F-040224009C02"></object>
  </div>
  <!-- End Get Dates -->
</div>
</body>
</html>

最新更新