Topic
  • 7 replies
  • Latest Post - ‏2013-03-13T08:20:22Z by adevicq
SystemAdmin
SystemAdmin
3180 Posts

Pinned topic Ole Objects and writing to Microsoft Word example and explanation

‏2013-03-07T18:22:30Z |
Is there a good reference to use to understand all the arguments for olePut, oleGet, oleMethod, etc.? I am trying to write a pretty simple script to print a log of what was done in dxl to a word document or a text file(but that seems more difficult) and between the forums, the reference manual, and browsing the web I still don't have the understanding I would like to have. I am using DOORS 9.3.

Thanks in advance,

Robert
Updated on 2013-03-13T08:20:22Z at 2013-03-13T08:20:22Z by adevicq
  • kbmurphy
    kbmurphy
    160 Posts

    Re: Ole Objects and writing to Microsoft Word example and explanation

    ‏2013-03-07T19:07:27Z  
    Take things one line at a time. Look at examples that work and copy them, and put a twist in.

    Also, read up on Visual Basic for Applications, particularly the Word object model. If you don't know VBA, you're not going to get anywhere in OLE Automation for Word.

    If you can write to a text file instead, it's WAY easier to do that, not harder. Look up Streams in the DXL reference manual.
  • llandale
    llandale
    3035 Posts

    Re: Ole Objects and writing to Microsoft Word example and explanation

    ‏2013-03-07T20:26:36Z  
    I'm struggling also.
    • olePut and oleGet deal with OleObject PROPERTIES
    • oleMethod obviously deal wth METHODS
    • put(AutoArgs) deal with PARAMETERS

    Reading the MSN web site
    [http://msdn.microsoft.com/en-us/library/bb214334(v=office.12).aspx]

    I see the important part of these top lines:
    • expression.AddLabel(Orientation, Left, Top, Width, Height)
    • expression Required. A variable that represents a CanvasShapes collection.

    Is that it deals with CanvasShapes. Your code would then look like this:
    • OleAutoObj oaoCanvas = whatever
    • OleAutoArgs oaaArgs = create
    • put(oaaArgs, "Orientation", "Left") // but Left may be an integer? Need to investigate that
    • oleMethod(oaoCanvas, "AddLabel", oaaArgs)

    I see for Word I've need to be very persnikety with nuance differences between "Application", "Documents", "Document", and "Selection" Objects. My variable names therefore have "App", "Docs", "Doc", or "Sel" respectively in their names.

    -Louie
  • SystemAdmin
    SystemAdmin
    3180 Posts

    Re: Ole Objects and writing to Microsoft Word example and explanation

    ‏2013-03-08T07:25:52Z  

    Hi

    First rule is: Write a code snippet in VBA and if it works then transform it to dxl.

    It is significant easiear to develope a vba-script inside of the excel or the word script editor and troubleshoote it there.

    If it works you have to use olePut, oleGet, oleMethod to move the code to dxl.

    This three routines returns an error string and so small routine will help:
     

    bool checkOleErrorString(string sErrorString) {
        if (sErrorString == null) { return(false) };
            logError(sErrorString dxlHere());
            return true;
    }
    

    Inside your "vba script code" you can use:

    checkOleErrorString(oleGet/Put/Method(...));
    


    In case of an error, the error itself is logged (and it's position in the code) and using the return value, you can handle an error.

    if checkOleErrorString(oleGet/Put/Method(...)) {
      // troubleshooting code
    }
    // standard code
    

     

    Best regards
    Wolfgang

     

     

     

     

     

     

    Updated on 2014-01-06T10:56:16Z at 2014-01-06T10:56:16Z by iron-man
  • SystemAdmin
    SystemAdmin
    3180 Posts

    Re: Ole Objects and writing to Microsoft Word example and explanation

    ‏2013-03-08T17:05:28Z  
    • kbmurphy
    • ‏2013-03-07T19:07:27Z
    Take things one line at a time. Look at examples that work and copy them, and put a twist in.

    Also, read up on Visual Basic for Applications, particularly the Word object model. If you don't know VBA, you're not going to get anywhere in OLE Automation for Word.

    If you can write to a text file instead, it's WAY easier to do that, not harder. Look up Streams in the DXL reference manual.
    kbmurphy,

    Any advice on how to create a .txt file in the dxl script?

    I see how to stream write to an already existing file but I am not sure how to create and open one for writing in dxl

    ---------------------{Code}-------------------------------
    //stream to .txt file

    //name for the .txt file
    //get the date and time of the log
    Date logDate = dateAndTime(today)
    string logDateString = stringOf(logDate)

    string outputFID = "Target Module Update Log "logDateString

    //create the .txt file

    //??? not sure how to do so in dxl ???

    //write the results log to the .txt file
    Stream logStream = write(string outputFID)

    ---------------------{End Code}-------------------------------

    Thanks in advance,

    rb24
  • kbmurphy
    kbmurphy
    160 Posts

    Re: Ole Objects and writing to Microsoft Word example and explanation

    ‏2013-03-08T18:39:38Z  
    kbmurphy,

    Any advice on how to create a .txt file in the dxl script?

    I see how to stream write to an already existing file but I am not sure how to create and open one for writing in dxl

    ---------------------{Code}-------------------------------
    //stream to .txt file

    //name for the .txt file
    //get the date and time of the log
    Date logDate = dateAndTime(today)
    string logDateString = stringOf(logDate)

    string outputFID = "Target Module Update Log "logDateString

    //create the .txt file

    //??? not sure how to do so in dxl ???

    //write the results log to the .txt file
    Stream logStream = write(string outputFID)

    ---------------------{End Code}-------------------------------

    Thanks in advance,

    rb24

    Off the top of my head:
     

    Date logDate = dateAndTime(today)
    string logDateString = stringOf(logDate)
     
    string outputFID = "Target Module Update Log " logDateString
     
    //create the .txt file
     
    Steam logStream = write("c:/temp/" outputFID)
    //??? not sure how to do so in dxl ???
     
    outputFID << "This is the first line of the log file.\n"
    outputFID << "This is the second line of the log file.\n"
     
    close logStream
    
    Updated on 2014-01-06T10:55:30Z at 2014-01-06T10:55:30Z by iron-man
  • SystemAdmin
    SystemAdmin
    3180 Posts

    Re: Ole Objects and writing to Microsoft Word example and explanation

    ‏2013-03-12T20:47:57Z  
    • kbmurphy
    • ‏2013-03-08T18:39:38Z

    Off the top of my head:
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Date logDate = dateAndTime(today) string logDateString = stringOf(logDate) string outputFID = "Target Module Update Log " logDateString //create the .txt file Steam logStream = write("c:/temp/" outputFID) //??? not sure how to do so in dxl ??? outputFID << "This is the first line of the log file.\n" outputFID << "This is the second line of the log file.\n" close logStream </pre>
    Thanks I got the stream working.
  • adevicq
    adevicq
    154 Posts

    Re: Ole Objects and writing to Microsoft Word example and explanation

    ‏2013-03-13T08:20:22Z  
    • kbmurphy
    • ‏2013-03-08T18:39:38Z

    Off the top of my head:
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Date logDate = dateAndTime(today) string logDateString = stringOf(logDate) string outputFID = "Target Module Update Log " logDateString //create the .txt file Steam logStream = write("c:/temp/" outputFID) //??? not sure how to do so in dxl ??? outputFID << "This is the first line of the log file.\n" outputFID << "This is the second line of the log file.\n" close logStream </pre>

    Hi,
    One suggestion: you can use

    string sTemp = getenv("temp")
    


    to retrieve the temp folder...
    regards,

    Updated on 2014-01-06T10:55:44Z at 2014-01-06T10:55:44Z by iron-man