从外部脚本文件加载子例程 [英] Load Subroutines From External Script File

查看:61
本文介绍了从外部脚本文件加载子例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将子例程放在一个外部文件中.当我按下帮助按钮时,它会弹出错误消息.即使在启动时,它也会显示错误.如果将scripts.vbs的内容放在HTA中,它们会正常工作.

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.

这是代码:

scripts.vbs文件的内容:

Sub Window_Onload
  Msgbox "welcome"
end sub

Sub Help
  MsgBox "This is an example of progressbar in HTA written by Fredledingue.",,MyTitle
End Sub

HTA文件的内容:

<script type="text/vbscript" src="scripts.vbs">
</script>

<body bgcolor="GreenYellow">
<input id="BtnHelp" type="button" value="Help" onclick="Help">

推荐答案

只要HTA和VBScript文件位于同一文件夹中,就可以导入这样的脚本文件.您需要确保<script>标记已关闭:

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).

话虽如此,我建议不要将HTA的代码外部化,因为它会降低移动性.自包含的HTA可以轻松复制到您喜欢的任何位置.将多个文件放在一起的需求对此有负面影响.

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.

这篇关于从外部脚本文件加载子例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆