01-21-2013 12:08 AM
Here are a few idiosyncracies I've discovered in the past couple days that have caused me more than a little grief. I think I understand why they work the way they do, but it sure wasn't obvious to this newbie what I was doing wrong.
1. When a registered user command script is edited and saved, all the global variables are erased.
2. When a registered user command script is edited and saved, all files registered as user commands are executed.
3. Item 1 happens before item 2.
This bit me in the behind when I used the TangentCursor_event.vbs example as the basis for my own code...
'------------------------------------------------------------------------------- ' Name : --- ' Copyright(c) : National Instruments Ireland Resources Limited ' Author : NI '------------------------------------------------------------------------------- Option Explicit 'Forces the explicit declaration of all the variables in a script. GlobalDim("oVIEWTCursorM") Set oVIEWTCursorM = new VIEW_Tangent_Cursor '--- Registered Event Handler --- Sub TangentCursor(oCursor) ' <snip> ' Calculates tangent Call oVIEWTCursorM.OnCursorHasChanged(oCursor) End Sub '--- Event Handler Class --- Class VIEW_Tangent_Cursor Public Function OnCursorHasChanged(oCursor) ' <snip> End Function End Class
...except I tried to move the GlobalDim and/or the object instantiation to other script files at various points in time. Since this file is registered as a user command (because the TangentCursor function is an event handler) it was executing at times I didn't expect, which meant the global variable was neither being declared nor set depending on what I was trying to do at any given point, and which led to all sorts of mysterious error messages and apparently inconsistent behavior.
*sigh* Learning a new api/language/technology can be fun, but it sure is frustrating at times.
01-21-2013 08:15 PM
When you say that you moved the global variable and object instantiation at various points in time, do you mean that you define these things on other scripts? Are there times that you don't do this?
Can you provide more information on the type of inconsistent behavior that occurred?
Can you provide screenshots of the errors you were receiving?
01-22-2013 01:57 AM - edited 01-22-2013 01:58 AM
"When you say that you moved the global variable and object instantiation at various points in time, do you mean that you define these things on other scripts?"
Yep, that's what I was trying to do. At various times while I was struggling with this I had zero, one, or both of those things on other scripts.
"Are there times that you don't do this?"
I've just started with Diadem scripting so it's probably not fair to make a claim one way or the other. But... the structure of the Tangent Cursor example didn't make a lot of sense to me. Having the global variable defined and instantiated on the same script that defines the class seems odd, especially when all the other globals are defined and instantiated in a different init script. I tried moving them from the TangentCursor_event file to the TangentCursor_init file, as well as putting all my globals in a separate file and various other strategies.
Also, I don't understand why the user command is on the same script as the class definition. It's more natural for me to put user command wrappers in a single file to be registered and leave the working code in other files. That way I'm only registering the event handling wrapper code, and given what I discovered about vanishing globals I want to edit user command code as little as possible.
"Can you provide more information on the type of inconsistent behavior that occurred?
Can you provide screenshots of the errors you were receiving?"
I struggled with this off and on over several days, but to the best of my current understanding the majority of the errors I ran into had to do with vanishing global variables (most of which were objects.) Sometimes my code would work, sometimes it wouldn't, and I couldn't figure out what was happening. I didn't even understand it enough to ask a coherent question--I had no repro case.
However, given what I learned yesterday I now think DIAdem was being entirely consistent; it was my lack of understanding of the conditions under which DIAdem erases global variables that led to my workflow creating an inconsistent execution environment. That, combined with my unfamiliarity with DIAdem and vbscript, led me to pursue lots of different ideas about what might be wrong and equally many different potential solutions. It was very much the shotgun approach.
If you need me to I can provide a few repro cases that generate the kinds of errors I was seeing and explain why they confused me, but the root cause for all of them is, as far as I know, that the global variables were erased without me knowing it. I'm guessing it's more of a user education issue than a software bug.
01-23-2013 04:21 PM
It sounds like you have taken a few different approaches in troubleshooting the behavior you observed. Is there a specific question that you would like more clarification on? If you can provide sample case along with steps taken that reproduces the behavior of the global variables being erased I can take a look at it as well.