# VBScript Function Calls from Script

VBScript or JScript functions defined in the macro module of a QlikView document can be called from the script. If a function called is not recognized as a standard script function, a check will be made to see if a custom functions resides in the module. This gives you a large degree of freedom to define your own functions. Using custom macro functions will of course be somewhat slower than executing the standard functions.

`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);`

## Transfer of Parameters

The following rules apply for parameter transfer of parameters between the load script and VBScript:

* Missing parameters are passed as NULL.
* If the actual expression evaluates to a valid number, the number is passed, else if the actual expression evaluates to a valid string, the string is passed, else NULL is passed.
* NULL is passed as VT\_EMPTY.
* Return values are treated in a natural way.