# 從指令碼呼叫 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` ` ` `載入` `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 之間參數的參數傳輸會套用下列規則︰

* 遺失的參數會傳遞為 NULL。
* 如果實際的運算式評估為有效的數字，則會傳遞該數字，否則如果實際的運算式評估為有效的字串，則會傳遞該字串，不然則傳遞 NULL。
* NULL 會傳遞為 VT\_EMPTY。
* 傳回值會以自然的方式處理。