Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: zalbina on September 14, 2012, 01:11:19 am
-
Hello,
I'm trying to add some tagged value to an attribute usind API and VBA, but doing this: att.TaggedValues.AddNew "bla","bla" does not work. Even no errors. Should I use SQL for it?
Thanks
-
I have this code for updating tagvalues:
Public Function addOrUpdateTaggedValue(myElement As EA.Element, tagName As String, tagValue As String) As EA.TaggedValue
Dim currentTag As EA.TaggedValue
'update all tagged values with the given name
For Each currentTag In myElement.TaggedValues
If currentTag.Name = tagName Then
currentTag.Value = tagValue
currentTag.Update
Set addOrUpdateTaggedValue = currentTag
End If
Next
'no tagged value found, so create it
If addOrUpdateTaggedValue Is Nothing Then
If Len(tagValue) > 256 Then
Set addOrUpdateTaggedValue = myElement.TaggedValues.AddNew(tagName, "Memo")
Else
Set addOrUpdateTaggedValue = myElement.TaggedValues.AddNew(tagName, "String")
End If
addOrUpdateTaggedValue.Value = tagValue
addOrUpdateTaggedValue.Update
End If
End Function
-
There were some earlier posts around this. Can not remember what the gotcha was off hand but I think the tagged value for an attribute is in a different bit of the object hierarchy (and with a different name) to element tagged values. If you check the help it tells you.
-
No you shouldn't need to resort to SQL.
The code posted by OpenIT Solutions should work just fine (seems somehow familiar ;))
Geert
-
Thank you everyone for your replays :).
-
This is, actually wrong:
Set addOrUpdateTaggedValue = myElement.TaggedValues.AddNew(tagName, "String")
Because this function returns EA.TaggedValue and AddNew function returns type Object. So, type mismatch. Is it possible to convert from one type to another in VBA?
Thanks.
-
Try changing EA.TaggedValue in EA.AttributeTag
Geert
-
Miracle. It does work when I've changed it to EA.AttributeTag.
Thanks a lot.