HTA中未终止的字符串常量从Path中的空格开始

时间:2014-04-25 00:59:33

标签: vbscript spaces hta

我是新来发布到Stack但是一直在使用这个网站来解决很多编码问题所以我知道一些基础知识。我已经尝试了几个小时(在一个问题上对我来说很重要)来解决这个问题。我正在创建一个本地工具(HTA)来最终管理CSV文件,但我仍然坚持第一部分。

我正在创建一个资源管理器类型选择工具,您可以在其中选择它将每个子文件夹作为按钮加载的根文件夹,除非子文件夹有一个空格,否则它会很好用#34; Unterminated String Constant"。我已解决了大多数问题,但由于我希望它使用此名称回拨,我不能简单地取出空间或替换它,因为点击它的按钮将无法正常工作。

任何帮助都会非常感激!

P.S。它未完成,我很抱歉没有评论或描述...... P.S.S.请告诉我你所看到的任何菜鸟......无论是网站礼仪还是编码。谢谢!!! Stackoverflow对我来说是一个巨大的帮助!!!

问题在线:

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>

2 个答案:

答案 0 :(得分:2)

错误的报价展示位置。拆分以使其更加明显

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

    strHtml = strHtml & Join(td,"")

答案 1 :(得分:0)

尝试使用这个有用的函数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>