用于隔离不应硬编码到脚本中的文本数据或数字数据。
<resource id="resourceID"> text or number </resource>
<resource> 元素允许您在 Windows 脚本 (.wsf) 文件中隔离要在脚本中引用的字符串或数字。例如,资源元素通常用于维护可本地化为其他语言的字符串。
要获取资源的值,就要调用 getResource 方法,将它传递给要使用的资源 ID。
将使用元素中的所有内容,包括空白区域(制表符、新行等)。
下面的代码定义资源 (errNonNumeric),如果变量 upperBound 不是数字,则返回资源的值。
<resource id="errNonNumeric">
Non-numeric value passed
</resource>
<script language="VBScript">
<![CDATA[
Function getRandomNumber(upperBound)
If IsNumeric(upperBound) Then
getRandomNumber = CInt(upperBound * Rnd + 1)
Else
getRandomNumber=getResource("errNonNumeric")
End If
End Function
]]>
</script>
<runtime> 元素 | <named> 元素 | <description> 元素 | <example> 元素 | <object> 元素 | <package> 元素 | getResource 方法