Page 1 of 1

Mini-Bug (Error 5) on script error

Posted: 28 May 2023 12:30
by PeterH
This script:

Code: Select all

"Main : test"
   $s = "cmd(op)";
   $w = "cmd";
   $r = replace($s, $w, '', 1, 0); // $w -> '', a ^= A, start = 0
has a bug: start has to start with 1, 0 is not defined.

Result:
Error: 5 (0x00000005)
Desc: Invalid procedure call or argument
Dll: 0
Proc: script_EvalFunction: replace

Source: XYplorer
XY ver: XYplorer 24.40.0005 - Lifetime License Enterprise
OS: Windows 7 Home Premium (Service Pack 1), 64-bit, Build 7601 (6.1)
Locale: 1031 (de-DE)
ANSI: 1252, ACP: 1252 (ANSI - Lateinisch I)
Font: Segoe UI 9, Segoe UI 9, DBCS: No
DPI: 96 (100%), 1680x1050

Date: 2023-05-28 11:57:42
I think it should just display a scripting error, shouldn't it?

The good thing: XY does not terminate (as I expected) - only the script does.
This way it seems like a bug in replace(), not in the script. Only found it by chance...
(Best would be Msg = Invalid argument value for 'start', I think :titter:
Though I don't expect this to happen. :whistle: )


By the way: building the replace() I thought of substr() etc: the 'first' char is '0'. So I coded start=0 - and failed. Is this consistent?
(For me 20 years ago and now it's so that the first tree, as well as the first character, is 1, not 0. So replace() counts 'correct'.
I said this when substr() was created, and say this still.
And yes, I know what an offset is. But a scripter should not have to think about that.
And no - nothing can be changed about that now.)

Re: Mini-Bug (Error 5) on script error

Posted: 30 May 2023 19:51
by admin
Bug confirmed and fixed.

In strings the first character is at position 1. Yes, I probably inherited this from VB. Now I wish I did not, but too late. :)

Re: Mini-Bug (Error 5) on script error

Posted: 30 May 2023 23:12
by PeterH
Maybe I should have protested louder then... :roll:

OK: I'll try to remember never to mention it again :beer: