Author Topic: Code VBScript is taking so long to execute  (Read 2313 times)

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Code VBScript is taking so long to execute
« on: August 03, 2023, 06:26:47 pm »
Hello guys, i have written a code in VBScript inside Enterprise Architect and it is working but it is taking so long to execute it. Is there any command in VBScript such as "Application.ScreenUpdating = False" in VBA, so my code does not last 3 minutes to execute?

steverumsby

  • EA User
  • **
  • Posts: 28
  • Karma: +3/-0
    • View Profile
Re: Code VBScript is taking so long to execute
« Reply #1 on: August 08, 2023, 01:23:23 am »
What is your script doing? It would be easier to help if you tell us a little more. There might be faster ways to do what you are doing.

For example, if you are using pure API access to get at the contexts of your model you will likely find that using SQL to read will be *much* faster. You'll still want to use API access to write any changes. I've reduced script runtimes from minutes to seconds once I realised this.

STeve.

PeteC

  • EA User
  • **
  • Posts: 91
  • Karma: +1/-0
    • View Profile
Re: Code VBScript is taking so long to execute
« Reply #2 on: August 18, 2023, 04:47:33 pm »
In addition to using SQL to find objects, I find that Jscript is faster than VBscript (there's also the option of Javascript but I've rarely used that).

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Code VBScript is taking so long to execute
« Reply #3 on: August 21, 2023, 09:10:06 pm »
You can use Repository.EnableUIUpdates

Works great if you are doing a lot of additions/deletes that cause the GUI to be updated.

Geert

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Code VBScript is taking so long to execute
« Reply #4 on: August 22, 2023, 10:52:31 pm »
Thanks for your help guys. In fact, the main problem is that my script is reading the same worksheet Excel 3 times and the worksheet contains 800 lines, so, event with Geert's Suggestion, the code takes long to be executed. I must change my code to optimise or i should evaluate the possibility of changing the language.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Code VBScript is taking so long to execute
« Reply #5 on: August 22, 2023, 11:10:59 pm »
Thanks for your help guys. In fact, the main problem is that my script is reading the same worksheet Excel 3 times and the worksheet contains 800 lines, so, event with Geert's Suggestion, the code takes long to be executed. I must change my code to optimise or i should evaluate the possibility of changing the language.
Only a poor craftsman blames his tools.

It's not the language that is the problem, it's probably the way you read your input from Excel. Reading excel can be very slow, if you don't do it efficiently.

Make sure you get all 800 lines at once using something like sheet.UsedRange.Value2
This will get everything into a two dimensional array.
Afterwards you can loop the array as much as you want.
Looping 800 records in an array will take no longer that a few miliseconds in any language.

Geert