问题
I want to put my subroutines in an external file. When I press the help button it pops up errors. Even at startup it shows errors. If I put the contents of scripts.vbs
within the HTA they work fine.
Here is the code:
Contents of scripts.vbs
file:
Sub Window_Onload
Msgbox "welcome"
end sub
Sub Help
MsgBox "This is an example of progressbar in HTA written by Fredledingue.",,MyTitle
End Sub
Contents of HTA file:
<script type="text/vbscript" src="scripts.vbs">
</script>
<body bgcolor="GreenYellow">
<input id="BtnHelp" type="button" value="Help" onclick="Help">
回答1:
Importing the script file like that should work, as long as the HTA and VBScript files are located in the same folder. You need to make sure that the <script>
tag is closed though:
<script type="text/vbscript" src="scripts.vbs"></script>
If you still get errors you need to show them (full error message, including error number and the line raising the error).
With that said, I'd recommend against externalizing code from HTAs, because it reduces mobility. A self-contained HTA can easily be copied to wherever you like. The need to keep several files together has a negative impact on that.
来源:https://stackoverflow.com/questions/31499095/load-subroutines-from-external-script-file