Dear Forum Members,
I am realatively new to STATA and new to Visual C#. As a part of a school assignment I would like to integrate them, I got stuck at OnFinish event.
I am using this manual, but it is only available for VB not C#:
http://www.stata.com/automation/
I could implement the creation of the stata object (stata.StataOLEApp), and I can run commands (DoCommand()), my problem is the following:
I am creating an easy user interface (WPF) and I would like to populate a combobox from the results of a Stata command. I send the command to stata with DoCommand which creates a variable when ready. I read the value of that variable with VariableData() method and use that value to populate the combobox. However, my program tries to populate the combobox before Stata finishes the command, so it ends up empty. I would like to pause the thread of my program until Stata finishes the command, for this I would like to use the UtilIsStataFreeEvent() method and catch the OnFinish event. Nevertheless, I am stuck at this point, the manual only illustrates VB not C#, and I am really new to C# event handling.
My code:
I created an event handler:
public void HandleCustomEvent(object sender, EventArgs a)
{
MessageBox.Show("Finito");
}
stata.StataOLEApp statapp = new stata.StataOLEApp();
... Stata commands
statapp.UtilIsStataFreeEvent();
statapp.OnFinish += new EventHandler(HandleCustomEvent);
But I get the error: Error 1 Cannot implicitly convert type 'System.EventHandler' to 'stata._IStataOLEAppEvents_OnFinishEventHandler'
Though based on this: http://msdn.microsoft.com/en-us/library/ms366768.aspx I should wirte: statapp.OnFinish += new CustomEventHandler(HandleCustomEvent);
But this CustomEventHandler is defined in the stata namespace?
Excuse me, I am new to C# and OOP too. Could you please help me with an example? Somebody here has some experience with this? Thank you!
I am realatively new to STATA and new to Visual C#. As a part of a school assignment I would like to integrate them, I got stuck at OnFinish event.
I am using this manual, but it is only available for VB not C#:
http://www.stata.com/automation/
I could implement the creation of the stata object (stata.StataOLEApp), and I can run commands (DoCommand()), my problem is the following:
I am creating an easy user interface (WPF) and I would like to populate a combobox from the results of a Stata command. I send the command to stata with DoCommand which creates a variable when ready. I read the value of that variable with VariableData() method and use that value to populate the combobox. However, my program tries to populate the combobox before Stata finishes the command, so it ends up empty. I would like to pause the thread of my program until Stata finishes the command, for this I would like to use the UtilIsStataFreeEvent() method and catch the OnFinish event. Nevertheless, I am stuck at this point, the manual only illustrates VB not C#, and I am really new to C# event handling.
My code:
I created an event handler:
public void HandleCustomEvent(object sender, EventArgs a)
{
MessageBox.Show("Finito");
}
stata.StataOLEApp statapp = new stata.StataOLEApp();
... Stata commands
statapp.UtilIsStataFreeEvent();
statapp.OnFinish += new EventHandler(HandleCustomEvent);
But I get the error: Error 1 Cannot implicitly convert type 'System.EventHandler' to 'stata._IStataOLEAppEvents_OnFinishEventHandler'
Though based on this: http://msdn.microsoft.com/en-us/library/ms366768.aspx I should wirte: statapp.OnFinish += new CustomEventHandler(HandleCustomEvent);
But this CustomEventHandler is defined in the stata namespace?
Excuse me, I am new to C# and OOP too. Could you please help me with an example? Somebody here has some experience with this? Thank you!
Comment