0

When running a .CATScript whose code was copied from the VBA environment and functions as intended when run in the VBA environment I get the following error:

The scripting engine has reported the following error:

Source: Microsoft VBScript runtime error

Description: Variable is undefined: 'Scripting'

Line: 9

Column: 4

How can I have this script use the "Microsoft Scripting Runtime" reference library?

Community
  • 1
  • 1
Laurens Ruben
  • 109
  • 5
  • 22
  • 1
    It looks like you haven't added it as a reference in your project yet. – braX Jan 15 '18 at 14:40
  • In the VBA environment I have ticked the required reference's box and my script works, however When I copy this script to notepad and save it as .CATScript it will give the mentioned error. Maybe there is a way to create/export the required .CATScript directly from the VBA environment which automatically includes all references. Or maybe I need to add code to the script so that it calls the required reference. – Laurens Ruben Jan 15 '18 at 14:46
  • If CATScript is like VBScript then you have to declare you variables as late bound. If so, google for VBScript vs VBA. – S Meaden Jan 15 '18 at 15:28
  • I'll add an answer to my question, could you confirm if this method would solve my problem? (I can't check if it's correct because I'm no longer at my workstation) – Laurens Ruben Jan 15 '18 at 16:29

2 Answers2

1

Your solution should work.

To be able to use "Scripting.Dictionary" in VBA, go to Tools->References and select "Microsoft Scripting Runtime".

C R Johnson
  • 964
  • 1
  • 5
  • 12
  • I believe my solution will indeed work, however I still have one last hurdle to jump before my script will finally work (probably). I'm using a "Collection" in my VBA code. See my new question here: https://stackoverflow.com/questions/48282675/catia-vba-to-catscript-for-type-collection – Laurens Ruben Jan 16 '18 at 13:46
0

I've searched on google for a bit and I believe the following would solve my problem:

'in original VBA code:
Dim dict As Scripting.Dictionary
Set dict = New Scripting.Dictionary

'To have this work in .CATScript, replace the code above with:
Dim dict
Set dict = CreateObject _
("Scripting.Dictionary")
Laurens Ruben
  • 109
  • 5
  • 22