Search code examples
vbscripthta

HTA - Unterminated string contants error


In my HTA file, I am trying to implement file browser button but for some reason HTA complains about unterminated string constant. I checked the code using a vbs file and it works but not in HTA

Code snippet

        Sub StartExec_OnClick           
            Dim objShell, objFile, BrowseForFile

            Set objShell = CreateObject("Shell.Application")
            aa = "about:<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>"
            Set objFile = objShell.Exec("mshta.exe " & Chr(34) & aa & Chr(34))
            BrowseForFile = objFile.StdOut.ReadLine

            Set objFile=Nothing
            Set objShell=Nothing
        End Sub

Solution

  • ...;resizeTo(0,0);</" & "script>"
    

    You have a problem with the parser incorrectly handling where the script ends, not the script you have enclosed in quotes but the script that includes the string. The </script> tag included in the string is seen as the closing tag of the outer script. Just split the string constant to avoid it.