Load Subroutines From External Script File

徘徊边缘 提交于 2019-12-11 10:36:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!