DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Properties of global dimmed object disappear when script is run again or another script is run manually

Solved!
Go to solution

Hello All,

as the title states the properties of an global object of an self-created class disappear when I rerun a script or run another script manually.
This issue does NOT appear when I call the second script with scriptstart()

Here is a short example to show you what I mean.

Script1:

Option Explicit

class cProperty
public Name
end class

Globaldim "sString"
sString = "DEF"

Globaldim "oObject"
set oObject = new cProperty
oObject.Name = "ABC"


call msgbox(oObject.Name) 'Outputs "ABC"

 Script2:

'class cProperty  'Declaring the class in Script2 won't make any difference
'public Name
'end class

call msgbox(sString) 'Always Outputs "DEF"
call msgbox(isObject(oObject)) 'Always Outputs "true"
call msgbox(oObject.Name) 'Outputs error "Object doesn't support this property or method" when run manually after Script1
'Outputs "ABC" when run with scriptstart("Script2")

 

It seems like when you want to access  the properties of the object, the reference of the object to the class is lost after the scriptengine has stopped running
I was just wondering that this happened and wanted to know if there is an easy workaround for that like declaring a class globally?

 


I recognized this behaviour because I want to accomplish the following task.
I have a dictionary with Objects as Items. The Objects are of an own class with properties which store information
On the first run of the script the user inputs different information which I store in the properties of the objects in the dictionary.

When the script is run again (provided the DIAdem has not been restarted) I want to display the information again.

 

 

Thank you for your help!


benebelt1

0 Kudos
Message 1 of 4
(1,335 Views)
Solution
Accepted by topic author benebelt1

Hi benebelt1,

 

When I create Script1.VBS and Script2.VBS files out of your code snippets, then go to the UserCommand dialog in DIAdem and add Script1.VBS to the list, I immediately see the MsgBox("ABC") output from Script1.VBS executing.  Then when I manually run Script2.VBS in the SCRIPT panel, I get all the correct outputs, including msgbox(oObject.Name) ==> "ABC".

 

I was testing all this in DIAdem 2021.  What version of DIAdem are you using?

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 2 of 4
(1,323 Views)

Hi Brad,

thanks for your reply!

I'm not sure why but when I tried to reply here NI.com security blocked this action and said it might be because I used certain words triggering the block. So I will just rewrite my message really short.

I don't know what you mean by "UserCommand dialog" but I loaded both scripts into the DIAdem script editor and ran Script1 first and then Script2. 

I'm currently using DIAdem2017 but I will try to install DIAdem2021 and run the code there.

 


benebelt1

0 Kudos
Message 3 of 4
(1,297 Views)

Hi Brad,

so I installed DIAdem2021 and it didn't work either.
Then I did some research on UserCommands you told me about and tried to understand what they do and realized that the solution is indeed quite simple.

What I did before was to call

scriptinclude()

to include a .vbs which contains different classes. But after the script has stopped running those classes probably weren't registered anymore and the information about the class structure wasn't stored in the object itself either. So accessing the properties of the object wouldn't work.

So the easy solution is to just run

if not scriptcmdIsLoaded("Script1.VBS") then
scriptcmdadd(PathOfScript & "Script1.VBS","permanent")
end if

at the beginning of Script2.VBS to ensure the classes are registered as long as DIAdem is running on one occassion.

Didn't know about the advantages of UserCommands or even about UserCommands themselves before.

Thank you very much!


benebelt1

0 Kudos
Message 4 of 4
(1,293 Views)