![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Counting Multiple Enumerated values Topic Summary: Show how many enumerated values are selected for an object Created On: 29-Sep-2005 16:20 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
The powers that be at my design center want to evaluate requirements based on how many enumerations are selected in a specific atribute. For example if the multi-valued enumeration has 6 possible entries and 3 are selected then a value of 3 needs to be displayed.
Has anyone else done this before? |
|
![]() |
|
![]() |
|
Sounds like an attribute dxl is needed (think the following should do you assuming you can read it, think someone in Telelogic has stuffed up this forum)
string MyAttribName = "My Enumerated Attribute"
AttrDef ad = find(current Module,MyAttribName)
AttrType at = ad.type
int i
int count=0
for(i=0;i
------------------------- Regards, Richard Good |
|
![]() |
|
![]() |
|
These facts may help: When you get the enumerated attr value the enumerations are separated by EOL characters, '\n'. Thus you algorithm is: if the Value is null then the result is zero; otherwise the result is the number of '\n' chararters found +1. You can find the number of EOLs by putting the value in a buffer and iteratively using the "contains(buff, char)" command. Looks something like attached.
- Louie |
|
![]() |
|
![]() |
|
I forgot to say that given the NameEnumAttr, you could derive the AttrDef, then the AttrType, then the number of Codes and the Codes themselves, then loop through the obj attribute checking for isMember(). The above code is easier, and on 2nd thought I think I'd change the function to accept the string Value and change the name of the function to "CountParagraphs"; then it could be used for other things that only we nit-wits care about.
- Louie |
|
![]() |
|
![]() |
|
Since '\n' is the newline character, perhaps "CountLines" would be a better name?
|
|
![]() |
|
![]() |
|
Louie - Can you help me by expanding on this? I need to count the number of instances of the use of each enumeration (multi-valued attr). i.e. an object can have a value of MEC and another object can have a value of MEC and C2MC. The count would then be:
MEC 2 C2MC 1 I tried using: if (isMember((current Object)."Allocation", "MEC")) then { allocCount1++} if (isMember((current Object)."Allocation", "C2MC")) then { allocCount2++} where allocCount1 counts all instances of MEC and allocCount2 counts C2MC, etc., but it doesn't give me the correct metrics. Thanks. |
|
![]() |
|
![]() |
|
Doh!
I replaced (current Object) with o in the isMember() function: if (isMember((current Object)."Allocation", "MEC")) then { allocCount1++} changed to if (isMember(o."Allocation", "MEC")) then { allocCount1++} and it works. |
|
![]() |
|
![]() |
|
Be advised that if attribute "Allocation" doesn't exist or if "MEC" or "C2MC" enumerations don't exist, your code will abort with DXL errors. You can check ahead of time or can surround your code with "noError()" then "ErrMess = lastError()", so that the DXL keep going.
- Louie |
|
![]() |
|
![]() |
|
Thanks Louie. I'll be sure to add that handler. Udaman.
|
|
![]() |
|
![]() |
|
Yes you are right.
I do a great deal of exporting reports in text format and then invoking Word to display it. I thus tend to think in terms of MS-Word and therein '\n' is an end of the paragraph (or table row). Perhaps "CountEOLs" may be appropriate. - Louie |
|
![]() |
|
![]() |
|
Rob,
Attached is an example using the methods that Louie outlined, where the enumeration values are not hard-coded in the DXL, but determined from the Attribute Type definition. ------------------------- Michael Sutherland michael@galactic-solutions.com http://galactic-solutions.com Edited: 7-Nov-2005 at 18:04 by Michael Sutherland |
|
![]() |
|
![]() |
|
Don't forget to insure that the at.type "" == "Enumeration", otherwise your at.size will cause DXL errors.
- Louie |
|
![]() |
|
![]() |
|
I have copy and paste this code and change the bValue and attribute type and get an error at
if (Offset < 0) Found = false invalue use of (if) what does that mean I'm not a programmer |
|
![]() |
|
![]() |
|
Make sure you didn't accidentally delete a (, ), {, or } somewhere above that.
------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Counting Multiple Enumerated values
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.