Catia VBA to .CATScript for type “Collection”

别等时光非礼了梦想. 提交于 2019-12-02 04:35:30

Either you have to use arrays, and manage the resizing yourself as you add and delete items to/from it, or you can use a dictionary and manage the keys as integers. I usually do the latter.

'create dictionary
set dict = CreateObject("Scripting.Dictionary")

'add object
dict.add dict.count,objectOrValue

'loop
for i = 0 to dict.count -1
   objectOrValue = dict.item(i)
   ...
next

This should behave much like a zero-based collection if you want to keep the one-based behavior of the vba collection use "dict.count+1" as the key

For the posted code to behave in the same way in VBScript as it would in VBA the following could be used:

Dim docsToSave
Set docsToSave = CreateObject("Scripting.Dictionary")

Dim toRemove
Set toRemove = CreateObject("Scripting.Dictionary")

...
More Code
...

For i = 0 To toRemove.Count - 1
    docsToSave.Remove (toRemove.keys()(i))
Next

Furthermore, to add to the Dictionary a different syntax is used compared to a Collection:

'VBA-code for a collection:
toRemove.Add (x)

'VBScript for a dictionary:
Call toRemove.Add(x, i)

These changes were sufficient for me to have my VBA-script work in VBScript.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!