Page 1 of 1

Problems of executing JScript

Posted: Tue Jul 01, 2014 2:47 pm
by cphan
I've tried to run the following script in Sable but it did not work. I've got the error message "One of the commands on the button failed to execute. XCommand: Execute Script:JScript.test()". Would you please help me solve this problem? Thanks!

Code: Select all

function test()
{
    var rangeCount = GetNumberOfSubscriptRanges();
	for (var i=0;i<rangeCount;i++){
		var name = GetSubscriptRangeName(i);
		name = name.replace(/"/g,'\'');
		var elementCount = GetNumberOfSubscriptElements(name);
		for(var j = 0;j<elementCount;j++){
			var elementName = GetSubscriptElement(name,j);
			elementName = elementName.replace(/"/g,'\'');
		}
	}
}

Re: Problems of executing JScript

Posted: Tue Jul 01, 2014 4:59 pm
by Administrator
The following does not look right

Code: Select all

name = name.replace(/"/g,'\'');
Shouldn't it be something like

Code: Select all

name = name.replace("g","a'');

Re: Problems of executing JScript

Posted: Wed Jul 02, 2014 7:36 am
by cphan
According to the manual of Microsoft Jscript (http://msdn.microsoft.com/en-us/library ... 90%29.aspx), name.replace(/"/g,'\''); replaces " by ', am i wrong?
By the way, i remove 2 lines with "replace" methods, it does not work either.

Re: Problems of executing JScript

Posted: Wed Jul 02, 2014 8:47 am
by Administrator
The function works fine. But you don't return any value from it, so Sable assumes it must have failed. Try the following.

Code: Select all

function test()
{
	var rangeCount = GetNumberOfSubscriptRanges();
	for (var i=0;i<rangeCount;i++)
	{
		var name = GetSubscriptRangeName(i);
		name = name.replace(/"/g,'\'');
		var elementCount = GetNumberOfSubscriptElements(name);
		for(var j = 0;j<elementCount;j++)
		{
			var elementName = GetSubscriptElement(name,j);
			elementName = elementName.replace(/"/g,'\'');
		}
	}
	return 1;
}

Re: Problems of executing JScript

Posted: Wed Jul 02, 2014 9:20 am
by cphan
It works like a charm in Sable Developer!
However, it does not work with Sable Runtime, i have the error
"Error: Microsoft JScript runtime error
Error executing : x= test()
Reason: expected object
Text:
Line:3"

Thanks a lot for your help!

Re: Problems of executing JScript

Posted: Wed Jul 02, 2014 2:48 pm
by Administrator
In Runtime, are you opening a SPK or the VNP file?

Re: Problems of executing JScript

Posted: Wed Jul 02, 2014 2:56 pm
by cphan
Neither of them works.

Re: Problems of executing JScript

Posted: Thu Jul 03, 2014 8:49 am
by Administrator
Can you send me the script file? The code works fine for me.

Re: Problems of executing JScript

Posted: Thu Jul 03, 2014 12:09 pm
by cphan
This is my project. Thanks for your help!

Re: Problems of executing JScript

Posted: Fri Jul 04, 2014 10:07 am
by Administrator
What happens for you in Runtime? I click the button and the code executes correctly. The function you've written doesn't do anything that would show on the screen.

Re: Problems of executing JScript

Posted: Fri Jul 04, 2014 12:53 pm
by cphan
I reinstall Sable, it works now. Thanks again for your help!