# 调自脚本的 VBScript 函数

定义在 QlikView 文档宏模式的 VBScript 或 JScript 函数可自脚本调用。如果调用的函数未确定为标准脚本函数，则将进行检查，查看在此模式中是否驻留有自定义函数。这让您可以有很大的自由空间定义您自己的函数。当然，使用自定义宏函数将比执行标准函数稍慢。

`Rem` `rem ***THIS IS VBSCRIPT CODE FROM THE MODULE*********` `rem**************************************************` `rem ********* Global variables ********************` `dim flag` `rem *******functions accessible from script *********` `rem ************ wrap for input box ******************` `function VBin(prompt)` `VBin=inputbox(prompt)` `end function` ` ` `rem ************ clear global flag ******************` `function VBclearFlag()` `flag=0` `end function` `rem ********* test if reference has passed ***********` `function VBrelPos(Ref, Current)` `if Ref=Current then` `VBRelPos="Reference"` `flag=1` `elseif flag=0 then` `VBRelPos="Before "&Ref&" in table"` `else` `VBRelPos="After "&Ref&" in table"` `end if` `end function` `// **************************************************` `// *************THIS IS THE SCRIPT *****************` `// *************************************************` ` ` `let MaxPop=VBin('Max population in millions :');` `// Ask limit` ` ` `let RefCountry=VBin('Reference country :');` ` // Ask ref.  ` ` ` `let dummy=VBclearFlag(); // Clears the global flag` ` ` `Load` `Country,recno(),` `Capital,` `"Area(km.sq)",` `"Population(mio)",` `VBrelPos('$(RefCountry)',Country)` `as RelativePos` `from country1.csv` `(ansi, txt, delimiter is ',', embedded labels)` `where "Population(mio)" <= $(MaxPop);`

## 转换参数

以下规则将应用于转换加载脚本和 VBScript 之间的参数。

* 丢失的参数作为空值传递。
* 如果真实表达式评估到有效的数字，则将传递数字。另外，如果真实表达式评估到有效字符串，则将传递字符串，否则作为空值传递。
* 空值作为 VT\_EMPTY 传递。
* 返回值以自然的方式处理。