For some reason the DXL interpreter does not take into account the fact that I am decrementing i at the end of the for loop. I am trying to navigate through the arrObj[] array by changing the value of "i". I have some buttons that increment(for next object) and decrement(for previous object) the value respectively. Doing the same thing with a while loop crashes the application.
Is there any way to control the index or will DXL always remember the previous value and increment it (even if the user changes it's value within the code).
Here's a snippet from my code:
for i in 0:(iTotalObj-1) do
{
sAuxType = arrObj[i]."ObjectType"
sAuxNr = number(arrObj[i]) " "
sAuxObjTxt = arrObj[i]."Object Text"
print "\nAfter FOR:"i ""
if sAuxType == "Test-Case" then
{
set(testContent,"Index number: (" number(arrObj[i]) ") -> " arrObj[i]."Object Heading" "")
set(expectedResults, " ")
fillRow(sTesterName,sCfgSW,sCfgHW,arrObj[i])
block(dtbox)
}
if sAuxType == "Test-Step" then
{
set(testContent,"Index number: (" number(arrObj[i]) ") -> " arrObj[i]."Object Text" "")
set(expectedResults,richTextWithOle(arrObj[i]."ExpectedResult"))
fillRow(sTesterName,sCfgSW,sCfgHW,arrObj[i])
block(dtbox)
}
if sAuxType == "Test-Case-Description" then
{
set(testContent,"Index number: (" number(arrObj[i]) ") -> " arrObj[i]."Object Text" "")
set(expectedResults, "Please check the description throroughly")
fillRow(sTesterName,sCfgSW,sCfgHW,arrObj[i])
block(dtbox)
arrObj[i].("TestResult " iTR "") = "n/a"
arrObj[i].("FR " iTR "") = "n/a"
}
i--
print "\nAfter DECREMENT:"i ""
}
On the output box I'll get the following:
After FOR:0
After DECREMENT:-1
After FOR:1
After DECREMENT:0
After FOR:2
After DECREMENT:1
With that type of for loop I believe DOORS is forcing i to the next value in the set. You should be able to use this type of loop instead:
for(i=0; i<(iTotalObj-1); i++) {
...
}
This loop will allow you to manipulate i inside the loop.
Related
Is there a way to get the attributes of a module without reading it?
I need to get that information for about 100 modules and it takes over 10 minutes if I have to read each module
I don't need to actually get the objects just the attributes available in the module
ModuleProperties should be faster. Try sth like this:
Item i = null
ModuleProperties mp = null
string sModuleAttribute = ""
string sError = ""
for i in project "/<myproject>" do {
if (type i == "Formal") {
sError = getProperties (moduleVersion module fullName i, mp)
if (null sError) {
for sModuleAttribute in mp do {
print fullName i "\t" sModuleAttribute "\t" mp.sModuleAttribute "\n"
}
} else {print sError "\n"}
delete mp
}
}
If you are also interested in the existence of attribute definitions for Objects, this might help
Item i = null
ModuleProperties mp = null
AttrDef ad = null
string sError = ""
for i in folder "/<myproject>" do {
if (type i == "Formal") {
sError = getProperties (moduleVersion module fullName i, mp)
if (null sError) {
for ad in mp do {
print fullName i "\t" ad.name "\t" ad.typeName "\t" ad.object "\t" ad.module "\n"
}
} else {print sError}
delete mp
}
}
I want to fetch enum attributes in a module using AttriBaseType and print it's elements.
Basically I want to know the usage of AttriBaseType in dxl.
For retrieving enum values, if you really want to use it explicitly, you can do it perhaps like this:
AttrType at
for at in current Module do {
print (at.name) " -- " (at.type) "\n"
AttrBaseType abt = at.type
if (abt == attrEnumeration) {
print "it is an " abt "\n"
int enumCount = at.size
int index
for (index = 0; index < enumCount; index++) {
// value, related number
print at.strings[index] ", " at.values[index] "\n"
}
print "\n"
}
}
I'm new to using DOORS and am trying to create a column/attribute that has the date of the last modification to the Object Text. I found the below code which uses "Last Modified On", but that that includes all attributes and I'm only concerned about the Object Text. Maybe there's a way to specifiy an attribute for this?
Date dMod
dMod = obj."Last Modified On"
dMod = dateAndTime(dMod)
display dMod ""
There's no such attribute on an attribute.
The only way to determine this is via the object's history. Below is the example script from DXL manual. The idea is to loop through the object's history until the history record's typeis modifyObjectand it's attrName equals 'Object Text'. Keep in mind, though, that the history in a module only goes back to the last baseline. So, you may have to browse through all baselines to find the history record you need. See Tony's "Smart History Viewer" at http://www.smartdxl.com/content/?page_id=125 for details.
// history DXL Example
/*
Example history DXL program.
Generate a report of the current Module's
history.
*/
// print a brief report of the history record
void print(History h) {
HistoryType ht = h.type
print h.author "\t" h.date "\t" ht "\t"
if (ht == createType ||
ht == modifyType ||
ht == deleteType) { // attribute type
print h.typeName
} else if (ht == createAttr ||
ht == modifyAttr ||
ht == deleteAttr) {
// attribute definition
print h.attrName
} else if (ht == createObject ||
ht == clipCopyObject ||
ht == modifyObject) { // object
print h.absNo
if (ht==modifyObject) {
// means an attribute has changed
string oldV = h.oldValue
string newV = h.newValue
print " (" h.attrName ":" oldV " -> " newV ")"
}
}
print "\n"
}
// Main program
History h
print "All history\n\n"
for h in current Module do print h
print "\nHistory for current Object\n\n"
for h in current Object do print h
print "\nNon object history\n\n"
for h in top current Module do print h
I'm learning Lua and probably don't have a great grasp on how the language works but I'm trying to create a split function for the string library:
string.split = function(str, delimiter)
-- A function which splits a string by a delimiter
values = {}
currentValue = ""
for i = 1, string.len(str) do
local character = string.sub(str, i, i)
if(character == delimiter) then
table.insert(values,currentValue)
currentValue = ""
else
currentValue = currentValue..character
end
end
-- clean up last item
table.insert(values,currentValue)
return vaules
end
values is not nil if I print it out before the return, but if I call t = string.split("hello world", " "), t will be nil. I'm not quite sure why my table is disappearing
You have a typo in your return statement.
vaules
Instead of values.
vaules is nil of course.
Another advice: make variables local wherever possible.
I have this code written in Lua, it's just an example code, because the actual one I'm using is bigger than this, but this is the part I'm having problems.
Does anyone know why when I try to print what's inside the table t I get nil as result?
t = {
{name="John",sex="M",age=19},
{name="Susan",sex="F",age=20}
}
for _ in ipairs(t) do
print("NAME: " .. t.name)
print("SEX: " .. t.sex)
print("AGE: " .. t.age)
print("\n")
end
I mean, this is the result I get when I run the code:
attempt to concatenate field 'name' (a nil value)
Iterating over t doesn't change t. You need to specify where to put the values you are iterating over, and use those variables.
local t = {
{name="John",sex="M",age=19},
{name="Susan",sex="F",age=20}
}
for index, value in ipairs(t) do
print("NAME: " .. value.name)
print("SEX: " .. value.sex)
print("AGE: " .. value.age)
print("\n")
end