Using COM from a R script - r

I woud like to be able to start and call a COM object from within a R script (in Windows obviously). There is a library called RDCOM http://www.omegahat.net/RDCOMClient/ but
it does not support VARIANT data types - and the COM object
expects VARIANT as parameters and returns arrays in them
is it maintained? are there active alternatives?
What I need to call is a function defined like this in the .idl file (the idl file gets compiled to create a COM object - not important except if you want to know the exact deeclaration of the object)
[id(3), helpstring("method GetQuestionList")] HRESULT GetQuestionList([out] VARIANT* nQuestionCount,[out] VARIANT* arrNames, [out] VARIANT* arrIndents, [out] VARIANT* arrTypes);
In this method the fields are passed by reference - in VB you would call it like this
Dim myObject = CreateObject("AskiaAPI.Analyse")
Dim arrIndents, nQuestionCount, arrNames, arrTypes As Object
myObject.GetQuestionList(nQuestionCount, arrNames, arrIndents, arrTypes)
Dim nQuestion
For nQuestion = 0 To nQuestionCount - 1
lstResults.Items.Add(nQuestion & ": " & arrNames(nQuestion))
Next nQuestion
In the code above, the variables nQuestionCount, arrNames, arrIndents, arrTypes are initialised by GetQuestionList (that's why they are passed by reference). In that example, lstResults would be a ListBox used to display the content of one of the parameters.
Any hint or idea is welcome!

Related

DDE INITIATE failed. (3153)

Progress ABL : OpenEdge Release 11.6
Operation System: Windows 7
Microsoft Office: 2013
Description:
That is a Reporting Project. The Progress 4GL is used by report generation with the Office Word. And the DDE initiate is failed. I don't known what is the happen.
I reference the Progress Document, which said same the problem is solved by OpenEdge Release 11.5.1. But I don't think so. Now I hope every body give the help. Thanks
DDE INITIATE failed
DDE TESTING code
Issue Coding:
DEFINE VARIABLE ddeid AS INTEGER NO-UNDO.
DEFINE VARIABLE frame-handle AS HANDLE NO-UNDO.
CREATE FRAME frame-handle
ASSIGN visible = TRUE
hidden = TRUE.
DDE INITIATE ddeid FRAME frame-handle
APPLICATION "Excel" TOPIC "System".
Found the reason and solved
Missing the winword.exe path
Missing WinExec Procedure
Coding:
DEFINE VARIABLE ddeid AS INTEGER NO-UNDO.
DEFINE VARIABLE frame-handle AS HANDLE NO-UNDO.
DEFINE VARIABLE return-code AS INT NO-UNDO.
CREATE FRAME frame-handle
ASSIGN visible = TRUE
hidden = TRUE.
PROCEDURE WinExec EXTERNAL "KERNEL32.DLL":
DEFINE INPUT PARAMETER ProgramName AS CHARACTER.
DEFINE INPUT PARAMETER VisualStyle AS LONG.
DEFINE RETURN PARAMETER StatusCode AS LONG.
END PROCEDURE.
RUN WinExec(INPUT "C:\Program Files\Microsoft Office\Office15\winword.exe", INPUT 1, OUTPUT return-code).
DDE INITIATE ddeid FRAME frame-handle
APPLICATION "Winword" TOPIC "System".

Save an Excel sheet as PDF programatically through powerbuilder

There is a requirement to save an excel sheet as a pdf file programmatically through powerbuilder (Powerbuilder 12.5.1).
I run the code below; however, I am not getting the right results. Please let me know if I should do something different.
OLEObject ole_excel;
ole_excel = create OLEObject;
IF ( ole_excel.ConnectToObject(ls_DocPath) = 0 ) THEN
ole_excel.application.activeworkbook.SaveAs(ls_DocPath,17);
ole_excel.application.activeworkbook.ExportAsFixedFormat(0,ls_DocPath);
END IF;
....... (Parsing values from excel)
DESTROY ole_excel;
I have searched through this community and others for a solution but no luck so far. I tried using two different commands that I found during this search. Both of them return a null object reference error. It would be great if someone can point me in the right direction.
It looks to me like you need to have a reference to the 'activeworkbook'. This would be of type OLEobject so the declaration would be similar to: OLEobject lole_workbook.
Then you need to set this to the active work book. Look for the VBA code on Excel (should be in the Excel help) for something like a 'getactiveworkbook' method. You would then (in PB) need to do something like
lole_workbook = ole_excel.application.activeworkbook
This gets the reference for PB to the activeworkbook. Then do you saveas and etc. like this lole_workbook.SaveAs(ls_DocPath,17)
workBook.saveAs() documentation says that saveAs() has the following parameters:
SaveAs(Filename, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)
we need the two first params:
FileName - full path with filename and extension, for instance: c:\myfolder\file.pdf
FileFormat - predefined constant, that represents the target file format.
According to google (MS does not list pdf format constant for XLFileFormat), FileFormat for pdf is equal to 57
so, try to use the following call:
ole_excel.application.activeworkbook.SaveAs(ls_DocPath, 57);

How to write some amounts to a File?

I'm doing this program for a class; I have a listbox with 4 choices that are counted each time they're selected,and i'm supposed to write out the results to an out.File so that they can then be retrieved and displayed when asked to.
Here's an image,so you can see what i mean.
Here's the code i got for the file part so far:
'declare a streamwriter variable
Dim outFile As IO.StreamWriter
'open file for output
outFile = IO.File.CreateText("Commercials.txt")
'write to file
For intIndex As Integer = 0 To lstCommercial.Items.Count - 1
outFile.WriteLine(lstCommercial.Items(intIndex))
Next intIndex
'close th efile
outFile.Close()
So my problem is this,i can get everything to work except for it to write the totals to the file,with the result of not displaying. How do i go about doing this? What am i doing wrong in any case?
It depends on what lstCommercial.Items is.
If it is a Collection object, then you can get the index of an item using the following:
outFile.WriteLine(lstCommercial.Items.Item(intIndex))
If it is an array, then instead of using the Count property to find the length, you should rather use GetUpperBound(0) to find the last index:
For intIndex As Integer = 0 To lstCommercial.Items.GetUpperBound(0)
I have very little experience in Visual Basic so I am probably wrong, but I have just gathered this from reading Arrays in Visual Basic and Collection Object (Visual Basic).
Also, looking at the docs here, you may need to 'Flush' the buffer to the file before closing it:
outFile.Flush()
'close the file
outFile.Close()

Trying to set a QDeclarativeScriptString in a unit test (QTestLib)

I'm trying to create a benchmark for part of my 2D game framework (It's a QML extension) and I'm having problems to set a declarative script property of a QOBject.
The property declaration:
Q_PROPERTY(QDeclarativeScriptString script READ script WRITE setScript NOTIFY scriptChanged)
And one of my attempts to change the script is something like this:
ScriptBehavior *behavior = new ScriptBehavior(entity);
QDeclarativeProperty(behavior, "script").write("console.log(1);");
But it doesn't work (Run the benchmark, but don't write anything to te console).
I've tried to use setProperty and manually create a QDeclarativeScriptString and set the property, but nothing works.
When I try to create the QDeclarativeScriptString, It fails:
The code:
ScriptBehavior *behavior = new ScriptBehavior(entity);
QDeclarativeScriptString scriptString;
scriptString.setScript("console.log(1)");
behavior->setScript(scriptString);
The output:
QFATAL : UpdateBenchmark::behavior() Received signal 11
FAIL! : UpdateBenchmark::behavior() Received a fatal error.
Loc: [Unknown file(0)]
Any help?
Thanks

Vendors black box function can only be called successfully once

(first question here, sorry if I am breaking a piece of etiquette)
My site is running on an eCommerce back end provider that I subscribe to. They have everything in classic ASP. They have a black box function called import_products that I use to import a given text file into my site's database.
The problem is that if I call the function more than once, something breaks. Here is my example code:
for blah = 1 to 20
thisfilename = "fullcatalog_" & blah & ".csv"
Response.Write thisfilename & "<br>"
Response.Flush
Call Import_Products(3,thisfilename,1)
Next
Response.End
The first execution of the Import_Products function works fine. The second time I get:
Microsoft VBScript runtime error '800a0009'
Subscript out of range: 'i'
The filenames all exist. That part is fine. There are no bugs in my calling code. I have tried checking the value of "i" before each execution. The first time the value is blank, and before the second execution the value is "2". So I tried setting it to null during each loop iteration, but that didn't change the results at all.
I assume that the function is setting a variable or opening a connection during its execution, but not cleaning it up, and then not expecting it to already be set the second time. Is there any way to find out what this would be? Or somehow reset the condition back to nothing so that the function will be 'fresh'?
The function is in an unreadable include file so I can't see the code. Obviously a better solution would be to go with the company support, and I have a ticket it in with them, but it is like pulling teeth to get them to even acknowledge that there is a problem. Let alone solve it.
Thanks!
EDIT: Here is a further simplified example of calling the function. The first call works. The second call fails with the same error as above.
thisfilename = "fullcatalog_testfile.csv"
Call Import_Products(3,thisfilename,1)
Call Import_Products(3,thisfilename,1)
Response.End
The likely cause of the error are the two numeric parameters for the Import_Products subroutine.
Import_Products(???, FileName, ???)
The values are 3 and 1 in your example but you never explain what they do or what they are documented to do.
EDIT Since correcting the vender subroutine is impossible, but it always works for the first time it's called lets use an HTTP REDIRECT instead of a FOR LOOP so that it technically only gets called once per page execution.
www.mysite.tld/import.asp?current=1&end=20
curr = CInt(Request.QueryString("current"))
end = CInt(Request.QueryString("end"))
If curr <= end Then
thisfilename = "fullcatalog_" & curr & ".csv"
Call Import_Products(3,thisfilename,1)
Response.Redirect("www.mysite.tld/import.asp?current=" & (curr + 1) & "&end=" & end)
End If
note the above was written inside my browser and is untested so syntax errors may exist.

Resources