Hi Dan, Most of the reason I haven't released it yet is just that the code is very messy... but perhaps I can send you some stuff as an example. The main thing I did structurally is I created the main window of the project (which I just called main window - I'm strikingly uncreative) and then I have a classes called R and RCommand. The MainWindow form stores a public shared variable called R. Then, when you load the form (start the application) it launches and connects to the DCOM server. Public Class MainWindow Public Shared R As R Private Sub MainWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.webDisplay.DocumentText = "" LoadR() End Sub Private Sub LoadR() Try R = New R Catch MsgBox("This application requires the (D)COM server available from the comprehensive R archive network. Please install (D)COM and restart this application. If you have already installed the (D)COM server, then there appears to be a problem with that application. Please try re-installing the (D)COM server.") Me.Close() End Try End Sub .... End Class The "R" class you see here is one that I wrote... it looks like this... Imports STATCONNECTORSRVLib Imports StatConnectorCommonLib Imports System.Collections.ObjectModel Public Class R Dim RServ As StatConnector Sub Close() RServ.Close() End Sub Public Sub New() RServ = New StatConnector RServ.Init("R") End Sub Public Function Evaluate(ByVal command As String) As Object Dim rtrObj As Object Try rtrObj = RServ.Evaluate(command) Catch ex As Exception rtrObj = Nothing End Try Return rtrObj End Function .... End Class If you're familiar with the DCOM server, basically you should see what's happening... When the MainWindow opens, that form creates a new R class that never closes until it is explicitly closed. That R class, when it opens, creates a connection to R using the DCOM server. In that class are functions that replicate the various things the DCOM server does (such as evaluate). These functions then return whatever R returns to them.. The various Try/Catch blocks basically will fail if the DCOM server cannot connect - that's how that message box works. If the program can't connect to the DCOM server it will give that nice response and then close. Because "R" is a publicly shared variable in the MainWindow, from anywhere in the application you can type "MainWindow.R.Evaluate('2+2')" and it will execute and return the object result.
Now that's where things get a bit trickier... DCOM returns things as normal datatypes and you have to basically respond to them based on what they are... For this, I would recommend looking at the sort of data you need to get back and start playing with it... I used a somewhat complex HTML output so I spend a bunch of time in my code converting those results into an HTML format- you'd probably not want to do this... So yeah, I'd play around with what you need - you'll probably see what I'm talking about... Since it's returning a generic object, you don't know right away what type of object it is, so you do things like... "objRtr.GetType.ToString" and that lets you read the type, then you respond based on the type of object it returns... For example, if it's just a string, you can do "rtrText = CType(objRtr, String).ToString". I'm going to send this to the DCOM listserv as well in case anybody else is interested in my example... Dan, I've moved your address to the BCC so it won't be shared... Hope this helps, Mike _____ From: Dan Georgescu [mailto: XXXXX ] Sent: Tuesday, December 18, 2007 6:18 AM To: [EMAIL PROTECTED] Subject: R.net Hi Mike, I am trying to write a .Net GUI for an economic scenario generator. The ESG will be in R. I have been trying to link R and .net without much luck so far - my programming skills are not quite there yet. Your front-end does this and I was wondering whether I could have the source code for your project to speed things along. I hope this is alright - you mention in your post to the R D(COM) mailing list that you might be releasing this as open source in the future, so I hope I am not being too cheeky. Many thanks, Dan _____ Sounds like? How many syllables? Guess and win prizes with Search Charades! <http://www.searchcharades.com>
_______________________________________________ Rcom-l mailing list Rcom-l@mailman.csd.univie.ac.at http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l More information (including a Wiki) at http://rcom.univie.ac.at