Link Trace

Hi everyone, recently i am trying to the project whose description is given below.

For a given module, trace of all its incoming links one by one until the point that source link has no other links (either incoming or outgoing) and write the results in the form a matrix for each requirement with links.

Writing part is faisable, however I have two problems. One when i try to use the code i have written below, for the source object of my incoming link i write down the same object text of the target object. And when i want to loop in the database when i say TypeItem == "Link" and then open the module, it does not open the module however same works when i say TypeItem == "Formal"

Here is the code that i use:

// Follow Links
 
pragma runLim,0
#include <utils/ole.inc>
#include <utils/doctools/itfutil.inc>
checkPlatform "Microsoft Excel"
 
OleAutoObj objExcel = null
OleAutoObj objWorkbooks = null
OleAutoObj objWorkbook = null
OleAutoObj objSheet = null
OleAutoObj objCell = null
OleAutoArgs args   = create
 
bool excelInit() {
    objExcel = connectToApp(cObjExcelApplication, "Excel")
    if (null objExcel) return false
 
    makeVisible objExcel
 
    // get workbooks collection
    checkRes(oleGet(objExcel,cPropertyWorkbooks,objWorkbooks))
    if (null objWorkbooks) {
    ack "Unable to get workbooks collection"
        return false
    }
 
    // add one
    checkRes(oleMethod(objWorkbooks, cMethodAdd))
 
    // get active workbook
    checkRes(oleGet(objExcel,cPropertyActiveWorkbook,objWorkbook))
    if (null objWorkbook) {
        ack "Unable to get active workbook"
        return false
    }
    // get active sheet
    checkRes(oleGet(objWorkbook,cPropertyActiveSheet,objSheet))
    if (null objSheet) {
        ack "Unable to get active sheet"
        return false
    }
 
    return true    
}
 
string intToCol(int i) {
    string s = ""
    if ((i>=1) && (i<=256))
    {
        int d1 = (i-1) / 26
        int d2 = (i-1) % 26
        if (d1 > 0) 
        {
            s = charOf( d1-1 + intOf('A')) ""
        }
        s = s charOf( d2 + intOf('A')) ""
    }
    else
    {
        if (i>256)
        {
            ack "Too many columns"
        }
        else
        {
            ack "Invalid column reference :" i ""
        }
        halt
    }
    return (s)
}
 
void setCell(int row, int col, string s) {
    closeIfNonNull objCell
    clear(args)
    put(args, (intToCol col) row "")
    checkRes(oleGet(objSheet, cMethodRange,args, objCell))
 
    if (null objCell) {
        ack "Unable to get cell object"
        halt
    }
 
        // Excel considers a string starting with the following characters:-
        // An equal character (=), a plus character (+), a minus character (-) or the (@) character
        // to be the start of an excel formula, hence it throws an error "OLE method failed".
        // To avoid this we append "'" before the string.
 
    // Also, "numbers-numbers" or "numbers-numbers-numbers" (Eg: 14-3, 14-10-17) will be intrepreted as "Date" in Excel.
    // So we append "'" before those strings also.
 
    Regexp dateCheck = regexp "^([0-9]+-)+[0-9]+$"
 
    if( s[0:0] == "=" || s[0:0] == "+" || s[0:0] == "-" || s[0:0] == "@" || dateCheck s )
    {
                s = "'" s
    }
 
    checkRes(olePut(objCell, cPropertyValue, s))
}
 
Skip myOpenedModulesList = create()
 
int displayIncomingLinks(Object theObject, string theLinkType, int theSourceRow, int theSourceColumn )
{
        Link    theLink
        LinkRef theLinkRef
        string  theSourceModuleName
        Module  theModule
        Object  theSrcObject
        int     theNewSourceRow
 
        for theLinkRef in theObject <- theLinkType do {
                theSourceModuleName = fullName source (theLinkRef)
                if (! open module theSourceModuleName) {
                        theModule = read ( theSourceModuleName, false )
                        put(myOpenedModulesList, theSourceModuleName, theModule)
                }
        }
        for theLink in theObject <- theLinkType do {
                theSourceModuleName = fullName source ( theLink )
                theSrcObject = source ( theLink )
                setCell ( theSourceRow, theSourceColumn, theSourceModuleName ":" identifier(theSrcObject) "\n" theObject."Object Text" "" )
                theNewSourceRow = displayIncomingLinks ( theSrcObject, theLinkType, theSourceRow, theSourceColumn+1 )
                if ( theNewSourceRow > theSourceRow ) {
                        theSourceRow = theNewSourceRow
                }
                else {
                        theSourceRow++
                }
        }
        return ( theSourceRow )
}
 
int displayOutgoingLinks(Object theObject, string theLinkType, int theSourceRow, int theSourceColumn )
{
        Link    theLink
        string  theTargetModuleName
        Module  theModule
        Object  theSrcObject
        int     theNewSourceRow
 
        for theLink in theObject -> theLinkType do {
                theTargetModuleName = fullName target ( theLink )
                if (! open module theTargetModuleName) {
                        theModule = read ( theTargetModuleName, false )
                        put(myOpenedModulesList, theTargetModuleName, theModule)
                }
                theSrcObject = target ( theLink )
                setCell ( theSourceRow, theSourceColumn, theTargetModuleName ":" identifier(theSrcObject) "\n" theObject."Object Text" "" )
                theNewSourceRow = displayOutgoingLinks ( theSrcObject, theLinkType, theSourceRow, theSourceColumn+1 )
                if ( theNewSourceRow > theSourceRow ) {
                        theSourceRow = theNewSourceRow
                }
                else {
                        theSourceRow++
                }
        }
        return ( theSourceRow )
}
 
Object myObject
Module myModule
int myTargetRow, myTargetColumn
int mySourceRow, mySourceColumn
LinkRef myLinkRef
Link myLink
string myLinkName
Skip myIncomingLinksList = create()
Skip myOutgoingLinksList = create()
int numberOfIncomingLinks
Module myLinkModule
 
myTargetColumn = 1
mySourceColumn = 2
myTargetRow = 2
mySourceRow = 2
myModule = current Module
int selectedWay = 0
 
for myObject in myModule do {
        for myLink in myObject -> "*" do {
                myLinkModule = module(myLink)
                put(myOutgoingLinksList, fullName(myLinkModule), myLinkModule )
        }
        for myLinkRef in myObject <- "*" do {
                myLinkModule = module(myLinkRef)
                mySourceModuleName = fullName source (myLinkRef)
                if (! open module mySourceModuleName) {
                        myModule = read ( mySourceModuleName, false )
                        put(myOpenedModulesList, mySourceModuleName, myModule)          }
                put(myIncomingLinksList, fullName(myLinkModule), myLinkModule )
        }
}
 
string ways[] = { "Incoming", "Outgoing" }
string incomingLinks[] = { }
string outgoingLinks[] = { }
DB linkSelectionDB = create ( "Links Selection", styleStandard )
DBE wayDBE = radioBox ( linkSelectionDB, "Select link way : ", ways, 0 )
DBE incomingLinksDBE = list ( linkSelectionDB, "Incoming Links:", 3, incomingLinks )
DBE outgoingLinksDBE = list ( linkSelectionDB, "Outgoing Links:", 3, outgoingLinks )
int selectedIncomingLink = -1
int selectedOutgoingLink = -1
string selectedIncomingLinkName = ""
string selectedOutgoingLinkName = ""
void generateMatrix ( DB windowDB )
{
        excelInit()
        for myObject in myModule do {
                if ( ( (myObject."Object Heading" "") == "" ) || ( (myObject."Object Text" "") != "" ) ) {
                        setCell ( myTargetRow, myTargetColumn, (fullName myModule) ":" identifier(myObject) "\n" myObject."Object Text" "" )
                        if ( selectedWay == 0 )
                        {
                                mySourceRow = displayIncomingLinks ( myObject, selectedIncomingLinkName, myTargetRow, mySourceColumn )
                        }
                        else
                        {
                                mySourceRow = displayOutgoingLinks ( myObject, selectedOutgoingLinkName, myTargetRow, mySourceColumn )
                        }
                        if ( mySourceRow > myTargetRow ) {
                                myTargetRow = mySourceRow 
                        }
                        else {
                                myTargetRow++
                        }
                }
        }
}
DBE generateDBE = ok ( linkSelectionDB, "Generate", generateMatrix )
inactive ( generateDBE )
void doChangingLinkWay ( DBE elementDBE )
{
        selectedWay = get (wayDBE )
        if ( selectedWay == 0 )
        {
                inactive ( outgoingLinksDBE )
                active   ( incomingLinksDBE )
                if ( selectedIncomingLink == - 1 )
                {
                        inactive ( generateDBE )
                }
                else
                {
                        active ( generateDBE )
                }
        }
        else
        {
                inactive ( incomingLinksDBE )
                active   ( outgoingLinksDBE )
                if ( selectedOutgoingLink == - 1 )
                {
                        inactive ( generateDBE )
                }
                else
                {
                        active ( generateDBE )
                }
        }
}
set ( wayDBE, doChangingLinkWay )
void doSelectingIncomingLink ( DBE elementDBE )
{
        selectedIncomingLink = get ( incomingLinksDBE )
        selectedIncomingLinkName = get ( incomingLinksDBE )
        if ( selectedIncomingLink == -1 )
        {
                inactive ( generateDBE )
        }
        else
        {
                active ( generateDBE )
        }
}
set ( incomingLinksDBE, doSelectingIncomingLink )
void doSelectingOutgoingLink ( DBE elementDBE )
{
        selectedOutgoingLink = get ( outgoingLinksDBE )
        selectedOutgoingLinkName = get ( outgoingLinksDBE )
        if ( selectedOutgoingLink == -1 )
        {
                inactive ( generateDBE )
        }
        else
        {
                active ( generateDBE )
        }
}
set ( outgoingLinksDBE, doSelectingOutgoingLink )
realize(linkSelectionDB)
for myLinkName in myIncomingLinksList do
{
        insert (  incomingLinksDBE, noElems(incomingLinksDBE), (string key(myIncomingLinksList)) )
}
 
for myLinkName in myOutgoingLinksList do
{
        insert (  outgoingLinksDBE, noElems(outgoingLinksDBE), (string key(myOutgoingLinksList)) )
}
inactive ( outgoingLinksDBE )
show ( linkSelectionDB )
 
for myModule in myOpenedModulesList do
{
        close myModule
}
delete(myOpenedModulesList)  // DO NOT FORGET !!!
delete(myIncomingLinksList)  // DO NOT FORGET !!!
delete(myOutgoingLinksList)  // DO NOT FORGET !!!

 


Thanks in advance for making your helping hand as you do all the time.

 


SystemAdmin - Tue May 26 05:22:13 EDT 2009

Re: Link Trace
SystemAdmin - Tue May 26 11:15:55 EDT 2009

Thanks everone who read this question. I have resolved my problem.

Re: Link Trace
SystemAdmin - Thu Jul 30 11:00:07 EDT 2009

SystemAdmin - Tue May 26 11:15:55 EDT 2009
Thanks everone who read this question. I have resolved my problem.

Can you tell me how you did that please?