DO11: Scripting and arrays again :-(

So, this time just in VBScript and not even JScript (thanks for the vector fix there)... and I want to say this could have changed between beta's 5 and 6... but maybe I just hadn't been doing similar things to what I'm trying now under B6. I'll re-test in B5 if you think it's worth it. But I digress...

  • I've got a Script.Config property I've initialized as an Array in OnInit...
  • If I message out it's TypeName() during init... == Variant, and I can run array functions against it no problem
  • Once the script command method gets called, this remains true. SO LONG AS I don't use the scripts 'Configuration' interface to modify the default values in the array property.

Once I do so, normal array functions against the property throw an error:

A method was called unexpectedly (0x8000ffff)

...and sure enough, the properties' type has changed from 'Variant' to just 'Object'. Resetting the script config properties back to their default doesn't even return things to normal. I have to nuke the contents of the ScriptConfig.oxc file to get things even back to a normal 'default' working state. This is by the way, relevant to one of my previous posts about how deleting and re-adding scripts leaves remnants behind: DO11: Scriptconfig.oxc remains after script deletion

Sample script attached: ScriptCommand_vbtest.osp (1.55 KB)

Provided as an OSP package just for simplicity sake... load it in, run the VBTEST command it adds, and check the output window log... You'll see another error FIRST which I'm starting another topic for... but for this topic, you'll see that I can successfully run UBound() against the objScriptVT_ARRAY property to show it's "size". If you then goto the scripts listing in Prefs and use the Configure button to modify the property (I added another line that reads "Fourth") then re-run the VBTEST command, you'll see the error in the code box above, and an earlier message showing the TypeName value is now Object instead of variant. You should also see that resetting the property to defaults in the Configure dialog doesn't even "fix" things :frowning:.

Feedback welcome...

Since the last beta Opus will always turn arrays into Vector objects, but you can use them the same way you use arrays.

Ah, I was going to ask if that change you made because of the JScript issues extended to VBScript as well. Ok... but if that is the case, how do we run an array function like UBound() against the property? Why also does it work against an unmodified property, but then break when I use the Configuration interface to add a value to the array?

Should we stop using native array functions and just use the Vector methods you defined? For the UBound() question, would I just switch to using the Vextor.length|count|size properties instead - even if I hadn't explicitly created a new Vector object? These are also Script Config properties... so would the vector methods just 'work' because you said you always turn arrays into Vectors, or would I do something like:

initData.config.objScriptVT_ARRAY = DOpus.NewVector("First","Second","Third")

instead of what I had been doing:

initData.config.objScriptVT_ARRAY = Array("First","Second","Third")

When you assign an array to the ScriptConfig object it will initially store it unchanged, but when Opus reloads the properties from disk or regenerates the internal storage due to editing, arrays will be converted into Vectors and remain like that from then on.

So if you assign an array it will be initially treated as an array; for example, this would fail:

initData.config.objScriptVT_ARRAY = Array("First","Second","Third") DOpus.Output initData.config.objScriptVT_ARRAY.length ` fail - not a Vector yet

To avoid this inconsistency I would just switch to using Vectors completely - there's no real downside.

Vector.length (or size or count) is the equivalent of UBound().