Is there a way in HTA to read a file containing vbscript and dynamically add it to a subroutine ? so than when i click on a button that subroutine gets called having the vbscript which is read from the file having it ?
I have tried reading the file and storing it to a variable. and i know u cant execute a variable. so how do we achieve this ?
typically i need a way to populate data inside
<script language="VBScript">
..........
.........
text from the file
..........
.........
</script>
is this possible ? or if it cant be hard coded some how can run the script ?.. creating a Wscript shell and pointing to the file using cscript wont work cause im using other objects in the vbs that require HTA to work.
help is needed thanks :)
It is possible. You need to use the ExecuteGlobal() function to add your dynamic code to your HTA. Here's an example.
Code to dynamically import (let's call it c:\library.vbs):
Sub ImportedLater()
MsgBox "I am not part of the HTA. I was imported later."
End Sub
Ad then, in your HTA:
<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION>
</head>
<body>
<button onclick="Test()">Click me</button>
</body>
<script language="VBScript">
' Add code from VBS file to global scope...
ExecuteGlobal CreateObject("Scripting.FileSystemObject").OpenTextFile("c:\library.vbs").ReadAll()
Sub Test()
' Button clicked. Call an imported function...
ImportedLater
End Sub
</script>
</html>
This should display the message in the ImportedLater subroutine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With