Book a Demo

Author Topic: Same script but Excels execution differs from EAs  (Read 5306 times)

ddinh

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Same script but Excels execution differs from EAs
« on: February 06, 2012, 04:43:50 am »
Hello.
My issue is a little tricky

Consider this procedure :

Code: [Select]
sub TVSetObjectTaggedValue( theObject, taggedValueName as String, taggedValueValue as String, replaceExisting as Boolean)
if not theObject is nothing and Len(taggedValueName) > 0 then
      dim taggedValue as EA.TaggedValue
      set taggedValue = nothing                  
      if replaceExisting = true then
             set taggedValue = theObject.TaggedValues.GetByName( taggedValueName )
      end if
                        
      if taggedValue is nothing then
            set taggedValue = theObject.TaggedValues.AddNew( taggedValueName, taggedValueValue )
      else
            taggedValue.Value = taggedValueValue
      end if

      taggedValue.Update
end if
end sub

This function is taken from standard library, ive just "abstract" the type of the element in order to useit for elements as well as attributes and connector.

This code works when I execute it as an EA Script within EA.

This code fails with 'execution error 13 type incompatibility" on the following line :

Code: [Select]
set taggedValue = theObject.TaggedValues.AddNew( taggedValueName, taggedValueValue )when I run it as excel script.

I spied my arguments type and they are both String.
I thought it was due to "variant" type of my String so, I cast them but it didn't resolve the issue.
Then i made 3 differents methods for each type of "myObject" (thought polymorphism wasn't accepted) but the issue hasn't been solved neither.

I don't really know where the issue comes from, and why the behaviour in EA differs from Excel behaviour. Any help ?

 :-/
« Last Edit: February 06, 2012, 05:13:37 am by ddinh »

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Same script but Excels execution differs from
« Reply #1 on: February 06, 2012, 10:02:39 am »
In your example, can you please confirm what type of object "theObject" is?

The EA.TaggedValue type is only used by the Element.TaggedValues collection.  The Attribute.TaggedValues collection is a collection of type EA.AttributeTag.  The Connector.TaggedValues collection is a collection of type EA.ConnectorTag.

Also, maybe confirm that "theObject" does reference a valid object of the expected type.

ddinh

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Same script but Excels execution differs from
« Reply #2 on: February 06, 2012, 08:26:11 pm »
Indeed, I checked types yesterday and there is a different types of tagged values for element, attribute and connector. I will abandon my approach.

It's weird that the script in EA never raised this typing issue and executed properly (I used it for parsing my model and setting some default tagged values, and it had never crashed ...)
« Last Edit: February 06, 2012, 08:27:19 pm by ddinh »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Same script but Excels execution differs from
« Reply #3 on: February 06, 2012, 09:43:31 pm »
Isn't that because of the difference between VBA and VBScript?
IIRC VBA is strong typed while VBScript is not.
If that is the case it makes sense doesn't it?

Geert

ddinh

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Same script but Excels execution differs from
« Reply #4 on: February 06, 2012, 09:52:32 pm »
Maybe you are right.
I thought VBScript API of EA behaves the same than VBA API EA. But its seems not.

I got another typing issue : I cannot find the equivalent of the 2 following codes for the a EA.Connector

Code: [Select]
       Dim taggedValue As EA.taggedValue
        Set taggedValue = theElement.taggedValues.GetByName(taggedValueName)

Code: [Select]
       Dim currentAttributeTag As EA.AttributeTag
        Set currentAttributeTag = theAttribute.taggedValues.GetByName(taggedValueName)

The following lines raised an "action not supported error" :
Code: [Select]
       Dim currentConnectorTag As EA.connectorTag
        Set currentConnectorTag = theConnector.taggedValues.GetByName(taggedValueName)

you would say "its because <<getbyname>> is not in the API" if you refer to the library function. However the function "getbyname" is proposed with autocompletion... Don't really get it. Is there kind of issue regarding some autocompletion feature which are not supported by the VBA runner ?  :o

Thanks in advance for your help.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Same script but Excels execution differs from
« Reply #5 on: February 06, 2012, 10:32:09 pm »
Yes, common issue.
GetByName is an operation defined on the generic EA.Collection class, but it is only supported on some actual collections. I think there's a list of supported types somewhere in the documentation.
That is one of the reasons I've never used it. Whenever I need something like that I'll write it myself.

Geert

ddinh

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Same script but Excels execution differs from
« Reply #6 on: February 09, 2012, 03:45:50 am »
Thanks for the tip, issue fixed.
Hopefully Collection.AddNew(...) works with EA.Collection ...