When accessing the members of the WIA Vector object directly using the Vector's Item property, or using the default property, they are seen by JScript as numbers:
var v = new ActiveXObject('WIA.Vector');
v.SetFromString('This is a test', true, false);
for (var i = 1; i<= v.Count; i+=1) {
WScript.Echo(String.fromCharCode(v(i)));
}
However, if I use an Enumerator to iterate through the Vector:
var enumerator = new Enumerator(v);
enumerator.moveFirst();
while (!enumerator.atEnd()) {
WScript.Echo(String.fromCharCode(enumerator.item()));
enumerator.moveNext();
}
I get the following error under WScript / CScript:
enumerator.item() is not a number
typeof
returns unknown
:
WScript.Echo(typeof enumerator.item());
Presumably it's some sort of Automation type (as in this question) that only appears as a number, which is why typeof
returns unknown
.
How can I coerce this value to a "real" Javascript number?
Update
The following code in VBA:
Dim v As New Vector, item As Variant
v.SetFromString "This is a test", True, False
For Each item In v
Debug.Print TypeName(item)
Next
prints
Byte
Byte
...
So the question can be narrowed down to the Byte specific Automation type.