Jump to content

Module-level constants not handled properly by WEng?


Recommended Posts

Posted
It seems WEng does not handle module-level constants properly. It looks like WEng remembers user-defined constant names even after the script has terminated, and wants to keep them as constants until the user exits WEng.

For example, if I declare "Const MyConstant = 123" at module level (i.e. before Main()), the script runs fine the first time around. However, when the script is run a second time, WEng complains that “Name redefined: 'MyConstant'” and stops. Using "Private Const" changes nothing.

Is this a known issue?

Here's an example script that triggers this error, and the exception report generated upon the second run attempt.



Utility
epmtAny


Option Explicit

Const MyConstant = 123

Sub Main()

MsgBox "MyConstant = " & MyConstant

End Sub


]]>

2004-06-17T11:00:40

Exception report produced at 2011-01-18 11:03:33

Name redefined: 'MyConstant' raised at: 2011-01-18 11:03:25
2011-01-18 11:03:25: Message added: Failed to execute the script Testing12.wes2 Modified: 18/01/2011 11:02:37
2011-01-18 11:03:25: Exception raised in: WAsP Engineering:cScripter:Execute
2011-01-18 11:03:25: Message added: Could not invoke the script
2011-01-18 11:03:25: Exception raised in: WAsP Engineering:cMainform:InvokeScript
Latest thread started in: WAsP Engineering:cProgressMonitor:Class_Terminate
Posted
It's not a known issue, since we've never used Consts in these scripts, but in the context of a loaded workspace, this would constitute a re-definition of the constant, I suppose. Re-loading the workspace should clear the scripting context.

What about just using a normal variable instead of a constant?
Posted
I guess I will have to use a normal variable. This unfortunately defeats the purpose of module-level constants, visible by all procedures in the module.

No big deal. I just thought I would make you aware of this quirk rather than keep it to myself. Let me know if my posting volume gets too high!
Posted
Posts are welcome. Let's hope others are getting some benefit from these discussions too.

Module-level variables can also be seen by all the procedures: they don't need to be consts. You only lose the constancy, not the scope.
Posted
Aha, module-level variables work fine. I'm not sure I understand why WEng accepts re-declaration of variables but not of constants... Oh well!

Thanks for the help.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...