sahi

Unable to set a global variable


I want to use a function and the parameter I am passing should be set to global all the time. How can I do that? Here is my code:

function ReadExcelfunction($FileName,$SheetName,$RowNum,$ColNum,$Parameter)
{
    var $excel = _getExcel($FileName,$SheetName);
    var $excelData=$excel.getData();
    var $Parameter=$excelData[$RowNum][$ColNum];
    //_setGlobal($Parameter,$excelData[$RowNum][$ColNum]) -- Commented
}

Now suppose I pass the parameters as -- File sheet 1 1 Name.

What I want is this: name with the Value is stored as Global value.

Earlier I used _setGlobal($Parameter,$excelData[$RowNum][$ColNum]) which solved the purpose but this API has been removed and now I need to change my script.

I am using the sahi scripting language which is similar to JavaScript.


Solution

  • You don't need to use _setGlobal, you only need to declare a var before the function declaration. For example, you can declare a new Array and then set/get values just like _setGlobal.

    // www.google.com used as start URL
    var $globalVariable = new Array();
    
    function SetGlobalVariable(key, newValue) {
      $globalVariable[key] = newValue;
    }
    
    SetGlobalVariable('inputValue', 'stack overflow');
    _setValue(_textbox("q"), $globalVariable['inputValue']);